2022-04-15 02:46:18 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-04-15 04:03:42 +00:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:wind/message_item_view.dart';
|
|
|
|
import 'package:wind/nntp_client.dart';
|
|
|
|
import 'package:wind/thread_list_view.dart';
|
|
|
|
import 'package:wind/thread_model.dart';
|
|
|
|
|
|
|
|
class ThreadScreenArguments {
|
|
|
|
final ThreadItem item;
|
|
|
|
|
|
|
|
ThreadScreenArguments(this.item);
|
|
|
|
}
|
2022-04-15 02:46:18 +00:00
|
|
|
|
|
|
|
class ThreadScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => ThreadScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class ThreadScreenState extends State<ThreadScreen> {
|
2022-04-15 04:03:42 +00:00
|
|
|
late NNTPClient client;
|
|
|
|
late int threadNumber;
|
|
|
|
|
2022-04-15 02:46:18 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-04-15 04:03:42 +00:00
|
|
|
var args =
|
|
|
|
ModalRoute.of(context)!.settings.arguments as ThreadScreenArguments;
|
|
|
|
client = context.read<NNTPClient>();
|
|
|
|
threadNumber = args.item.number;
|
|
|
|
|
2022-04-15 02:46:18 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-04-15 04:03:42 +00:00
|
|
|
title: Text("Thread #${args.item.number}"),
|
2022-04-15 02:46:18 +00:00
|
|
|
),
|
2022-04-15 04:03:42 +00:00
|
|
|
body: Center(
|
|
|
|
child: Container(
|
|
|
|
width: 640,
|
|
|
|
child: FutureBuilder<List<MessageItem>>(
|
|
|
|
future: _fetch(context),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
List<MessageItem> data = List.from(snapshot.data!);
|
|
|
|
data.insert(
|
|
|
|
0,
|
|
|
|
MessageItem(args.item.id, args.item.number, args.item.subject,
|
|
|
|
args.item.author, args.item.date, args.item.body));
|
|
|
|
return _listView(data);
|
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
return Text("${snapshot.error}");
|
|
|
|
}
|
|
|
|
return Center(child: CircularProgressIndicator());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)),
|
2022-04-15 02:46:18 +00:00
|
|
|
);
|
|
|
|
}
|
2022-04-15 04:03:42 +00:00
|
|
|
|
|
|
|
Future<List<MessageItem>> _fetch(BuildContext context) async {
|
|
|
|
var model = context.read<ThreadModel>();
|
|
|
|
return await model.getThread(threadNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _listView(List<MessageItem> data) {
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: data.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return MessageItemView(item: data[index], isOpPost: index == 0);
|
|
|
|
});
|
|
|
|
}
|
2022-04-15 02:46:18 +00:00
|
|
|
}
|