mirror of
https://github.com/ChronosX88/wind.git
synced 2024-12-04 18:12:18 +00:00
Implement thread view update feature
This commit is contained in:
parent
987c48d530
commit
a0e45d81ff
@ -53,4 +53,8 @@ class ThreadModel extends ChangeNotifier {
|
||||
msg.addHeader("Newsgroups", client!.currentGroup!);
|
||||
return await client!.postArticle(msg);
|
||||
}
|
||||
|
||||
void update() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@ -22,36 +22,55 @@ class ThreadScreen extends StatefulWidget {
|
||||
|
||||
class ThreadScreenState extends State<ThreadScreen> {
|
||||
ThreadScreenState(this.threadNumber);
|
||||
|
||||
late ThreadModel model;
|
||||
late int threadNumber;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
model = Provider.of<ThreadModel>(context, listen: false);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Thread #${this.threadNumber}"),
|
||||
title: Text("Тред #${this.threadNumber}"),
|
||||
actions: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Обновление треда...')),
|
||||
);
|
||||
model.update();
|
||||
},
|
||||
label: const Text("Обновить"),
|
||||
style: TextButton.styleFrom(
|
||||
primary: Theme.of(context).colorScheme.onPrimary),
|
||||
icon: Icon(Icons.sync))
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: Container(
|
||||
width: 650,
|
||||
child: FutureBuilder<List<MessageItem>>(
|
||||
child: Consumer<ThreadModel>(
|
||||
builder: ((context, value, child) =>
|
||||
FutureBuilder<List<MessageItem>>(
|
||||
future: _fetch(context),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
List<MessageItem> data = List.from(snapshot.data!);
|
||||
data.insert(1, MessageItem("reply", 0, "", "", "", "")); // reply
|
||||
data.insert(
|
||||
1, MessageItem("reply", 0, "", "", "", "")); // reply
|
||||
return _listView(data);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("${snapshot.error}");
|
||||
}
|
||||
return Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
))),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<MessageItem>> _fetch(BuildContext context) async {
|
||||
var model = context.read<ThreadModel>();
|
||||
List<MessageItem> posts = [];
|
||||
|
||||
var threadPosts = await model.getThread(threadNumber);
|
||||
@ -145,13 +164,16 @@ class SendMessageFormState extends State<SendMessageForm> {
|
||||
listen: false)
|
||||
.postMessage(opPost,
|
||||
value.commentTextController.text)
|
||||
.then((value) {
|
||||
if (value == 240) {
|
||||
.then((responseCode) {
|
||||
if (responseCode == 240) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Пост отправлен!')),
|
||||
);
|
||||
Provider.of<ThreadModel>(context,
|
||||
listen: false)
|
||||
.update();
|
||||
}
|
||||
});
|
||||
value.commentTextController.text = "";
|
||||
|
Loading…
Reference in New Issue
Block a user