2022-04-14 19:17:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-04-15 02:46:18 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2022-04-14 19:17:47 +00:00
|
|
|
import 'package:wind/nntp_client.dart';
|
2022-04-15 02:46:18 +00:00
|
|
|
import 'package:wind/thread_list_model.dart';
|
|
|
|
|
|
|
|
class NewsgroupListView extends StatefulWidget {
|
|
|
|
NewsgroupListView({Key? key, required this.client}) : super(key: key);
|
2022-04-14 19:17:47 +00:00
|
|
|
|
|
|
|
final NNTPClient client;
|
|
|
|
|
2022-04-15 02:46:18 +00:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => new NewsgroupListViewState(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewsgroupListViewState extends State<NewsgroupListView> {
|
|
|
|
late NNTPClient client;
|
|
|
|
int _selectedIndex = -1;
|
|
|
|
|
|
|
|
NewsgroupListViewState(this.client);
|
2022-04-14 19:17:47 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder<List<GroupInfo>>(
|
|
|
|
future: _fetchList(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
List<GroupInfo> data = snapshot.data!;
|
2022-04-15 02:46:18 +00:00
|
|
|
return _newsgroupListView(data);
|
2022-04-14 19:17:47 +00:00
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
return Text("${snapshot.error}");
|
|
|
|
}
|
|
|
|
return Center(child: CircularProgressIndicator());
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<List<GroupInfo>> _fetchList() async {
|
|
|
|
return await client.getNewsGroupList();
|
|
|
|
}
|
|
|
|
|
2022-04-15 02:46:18 +00:00
|
|
|
Widget _newsgroupListView(List<GroupInfo> data) {
|
2022-04-14 19:17:47 +00:00
|
|
|
return ListView.builder(
|
2022-04-17 21:10:13 +00:00
|
|
|
controller: ScrollController(),
|
2022-04-15 02:46:18 +00:00
|
|
|
itemCount: data.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
|
|
|
style: ListTileStyle.drawer,
|
|
|
|
title: Text(data[index].name),
|
|
|
|
subtitle: Text(data[index].description),
|
|
|
|
selected: index == _selectedIndex,
|
|
|
|
onTap: () {
|
|
|
|
setState(() => _selectedIndex = index);
|
|
|
|
var model = context.read<ThreadListModel>();
|
|
|
|
model
|
|
|
|
.selectNewsgroup(data[index].name)
|
|
|
|
.whenComplete(() => null);
|
|
|
|
});
|
|
|
|
});
|
2022-04-14 19:17:47 +00:00
|
|
|
}
|
|
|
|
}
|