Initial commit
This commit is contained in:
82
lib/widgets/channel_list.dart
Normal file
82
lib/widgets/channel_list.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../models/stream_entry.dart';
|
||||
import '../providers/m3u_provider.dart';
|
||||
import '../player_screen.dart';
|
||||
|
||||
class ChannelList extends ConsumerWidget {
|
||||
final TextEditingController m3uController;
|
||||
|
||||
const ChannelList({super.key, required this.m3uController});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(channelListProvider);
|
||||
final selected = ref.watch(selectedChannelProvider);
|
||||
|
||||
return Container(
|
||||
width: 320,
|
||||
decoration: BoxDecoration(color: Colors.grey[900]),
|
||||
child: Column(children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Row(children: [
|
||||
const Expanded(
|
||||
child: Text('실시간 채널',
|
||||
style:
|
||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold))),
|
||||
IconButton(
|
||||
onPressed: () => ref
|
||||
.read(channelListProvider.notifier)
|
||||
.fetch(m3uController.text.trim()),
|
||||
icon: const Icon(Icons.refresh)),
|
||||
]),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: state.when(
|
||||
data: (list) {
|
||||
if (list.isEmpty)
|
||||
return const Center(child: Text('채널이 없습니다. M3U를 불러오세요.'));
|
||||
return ListView.separated(
|
||||
itemCount: list.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (context, idx) {
|
||||
final s = list[idx];
|
||||
final isSelected = selected?.url == s.url;
|
||||
return ListTile(
|
||||
selected: isSelected,
|
||||
title: Text(s.title, overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text(s.url,
|
||||
overflow: TextOverflow.ellipsis, maxLines: 1),
|
||||
onTap: () =>
|
||||
ref.read(selectedChannelProvider.notifier).state = s,
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.open_in_full),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PlayerScreen(
|
||||
videoPath: s.url, videoName: s.title))),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (e, st) => Center(
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Text('불러오기 실패: $e'),
|
||||
const SizedBox(height: 8),
|
||||
ElevatedButton(
|
||||
onPressed: () => ref
|
||||
.read(channelListProvider.notifier)
|
||||
.fetch(m3uController.text.trim()),
|
||||
child: const Text('다시시도'))
|
||||
])),
|
||||
),
|
||||
)
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
103
lib/widgets/m3u_sources_screen.dart
Normal file
103
lib/widgets/m3u_sources_screen.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
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('닫기'))
|
||||
])
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user