Skip to content

Commit b22ef67

Browse files
committed
main: Add a stub MessageListPage, with real fetch
1 parent 582a60b commit b22ef67

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

lib/main.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/material.dart';
22

3+
import 'api/model/model.dart';
4+
import 'api/route/messages.dart';
35
import 'store.dart';
46

57
void main() {
@@ -95,6 +97,69 @@ class HomePage extends StatelessWidget {
9597
Text('Zulip server version: ${store.initialSnapshot.zulip_version}'),
9698
Text(
9799
'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"))
98107
])));
99108
}
100109
}
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+
}

lib/store.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@ class PerAccountStore extends ChangeNotifier {
1717
// TODO log the time better
1818
if (kDebugMode) print("initial fetch time: ${t.inMilliseconds}ms");
1919

20-
return PerAccountStore(account: account, initialSnapshot: initialSnapshot);
20+
return PerAccountStore(
21+
account: account,
22+
connection: connection,
23+
initialSnapshot: initialSnapshot,
24+
);
2125
}
2226

2327
final Account account;
28+
final ApiConnection connection;
2429
final InitialSnapshot initialSnapshot; // TODO translate to a real model
2530

26-
PerAccountStore({required this.account, required this.initialSnapshot});
31+
PerAccountStore({
32+
required this.account,
33+
required this.connection,
34+
required this.initialSnapshot,
35+
});
2736
}
2837

2938
/// A scaffolding hack for while prototyping.

0 commit comments

Comments
 (0)