104 lines
3.9 KiB
Dart
104 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../providers/m3u_sources_provider.dart';
|
|
|
|
class M3uSourcesScreen extends ConsumerStatefulWidget {
|
|
const M3uSourcesScreen({super.key});
|
|
|
|
@override
|
|
ConsumerState<M3uSourcesScreen> createState() => _M3uSourcesScreenState();
|
|
}
|
|
|
|
class _M3uSourcesScreenState extends ConsumerState<M3uSourcesScreen> {
|
|
final TextEditingController _controller = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// load persisted sources
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ref.read(m3uSourcesProvider.notifier).load();
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = ref.watch(m3uSourcesProvider);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('M3U Sources')),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Column(children: [
|
|
Row(children: [
|
|
Expanded(
|
|
child: TextField(
|
|
controller: _controller,
|
|
decoration: const InputDecoration(
|
|
labelText: 'M3U URL',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
)),
|
|
const SizedBox(width: 8),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
final url = _controller.text.trim();
|
|
if (url.isEmpty) return;
|
|
await ref.read(m3uSourcesProvider.notifier).add(url);
|
|
_controller.clear();
|
|
},
|
|
child: const Text('추가'))
|
|
]),
|
|
const SizedBox(height: 12),
|
|
Expanded(
|
|
child: state.sources.isEmpty
|
|
? const Center(child: Text('저장된 M3U 소스가 없습니다.'))
|
|
: ListView.separated(
|
|
itemCount: state.sources.length,
|
|
separatorBuilder: (_, __) => const Divider(height: 1),
|
|
itemBuilder: (context, idx) {
|
|
final url = state.sources[idx];
|
|
final isDefault = url == state.defaultUrl;
|
|
return ListTile(
|
|
title:
|
|
Text(url, style: const TextStyle(fontSize: 14)),
|
|
leading: IconButton(
|
|
icon: Icon(
|
|
isDefault ? Icons.star : Icons.star_border),
|
|
onPressed: () async {
|
|
await ref
|
|
.read(m3uSourcesProvider.notifier)
|
|
.setDefault(isDefault ? null : url);
|
|
},
|
|
tooltip:
|
|
isDefault ? 'Default source' : 'Set default',
|
|
),
|
|
trailing:
|
|
Row(mainAxisSize: MainAxisSize.min, children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.delete_outline),
|
|
onPressed: () async {
|
|
await ref
|
|
.read(m3uSourcesProvider.notifier)
|
|
.remove(url);
|
|
},
|
|
)
|
|
]),
|
|
onTap: () {
|
|
// Close and return the selected URL
|
|
Navigator.of(context).pop(url);
|
|
},
|
|
);
|
|
})),
|
|
const SizedBox(height: 8),
|
|
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('닫기'))
|
|
])
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|