|
1 | 1 | import 'package:flutter/material.dart';
|
2 | 2 |
|
| 3 | +import 'api/model/model.dart'; |
| 4 | +import 'api/route/messages.dart'; |
3 | 5 | import 'store.dart';
|
4 | 6 |
|
5 | 7 | void main() {
|
@@ -95,6 +97,69 @@ class HomePage extends StatelessWidget {
|
95 | 97 | Text('Zulip server version: ${store.initialSnapshot.zulip_version}'),
|
96 | 98 | Text(
|
97 | 99 | 'Subscribed to ${store.initialSnapshot.subscriptions.length} streams'),
|
| 100 | + const SizedBox(height: 16), |
| 101 | + ElevatedButton( |
| 102 | + onPressed: () => Navigator.push( |
| 103 | + context, |
| 104 | + MaterialPageRoute( |
| 105 | + builder: (context) => const MessageListPage())), |
| 106 | + child: const Text("All messages")) |
98 | 107 | ])));
|
99 | 108 | }
|
100 | 109 | }
|
| 110 | + |
| 111 | +class MessageListPage extends StatefulWidget { |
| 112 | + const MessageListPage({Key? key}) : super(key: key); |
| 113 | + |
| 114 | + @override |
| 115 | + State<MessageListPage> createState() => _MessageListPageState(); |
| 116 | +} |
| 117 | + |
| 118 | +class _MessageListPageState extends State<MessageListPage> { |
| 119 | + @override |
| 120 | + Widget build(BuildContext context) { |
| 121 | + return Scaffold( |
| 122 | + appBar: AppBar(title: const Text("Some messages")), |
| 123 | + body: Center( |
| 124 | + child: Column(children: const [ |
| 125 | + Expanded(child: MessageList()), |
| 126 | + SizedBox( |
| 127 | + height: 80, |
| 128 | + child: Center(child: Text("(Compose box goes here.)"))), |
| 129 | + ]))); |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +class MessageList extends StatefulWidget { |
| 134 | + const MessageList({Key? key}) : super(key: key); |
| 135 | + |
| 136 | + @override |
| 137 | + State<StatefulWidget> createState() => _MessageListState(); |
| 138 | +} |
| 139 | + |
| 140 | +class _MessageListState extends State<MessageList> { |
| 141 | + final List<Message> messages = []; // TODO move state up to store |
| 142 | + bool fetched = false; |
| 143 | + |
| 144 | + @override |
| 145 | + void didChangeDependencies() { |
| 146 | + super.didChangeDependencies(); |
| 147 | + _fetch(); |
| 148 | + } |
| 149 | + |
| 150 | + Future<void> _fetch() async { |
| 151 | + final store = PerAccountStoreWidget.of(context); |
| 152 | + final result = |
| 153 | + await getMessages(store.connection, num_before: 10, num_after: 10); |
| 154 | + setState(() { |
| 155 | + messages.addAll(result.messages); |
| 156 | + fetched = true; |
| 157 | + }); |
| 158 | + } |
| 159 | + |
| 160 | + @override |
| 161 | + Widget build(BuildContext context) { |
| 162 | + if (!fetched) return const Center(child: CircularProgressIndicator()); |
| 163 | + return Center(child: Text("Got ${messages.length} messages")); |
| 164 | + } |
| 165 | +} |
0 commit comments