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('다시시도'))
|
||||
])),
|
||||
),
|
||||
)
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user