Skip to content

Commit 368f3fb

Browse files
committed
DEV DEMO exercise MentionAutocompleteView
Steps: - Go to the message list - Type a mention autocomplete query (sans "@") in the compose box "topic" field - Pop the route (like with the back button) - See debug prints with the matching user IDs
1 parent c0a97d7 commit 368f3fb

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

lib/widgets/compose_box.dart

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import 'package:file_picker/file_picker.dart';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
55
import 'package:image_picker/image_picker.dart';
6-
import 'dialog.dart';
76

7+
import '../model/autocomplete.dart';
8+
import '../model/narrow.dart';
9+
import '../model/store.dart';
10+
import 'dialog.dart';
811
import '../api/route/messages.dart';
912
import 'store.dart';
1013

@@ -167,9 +170,36 @@ class _StreamContentInput extends StatefulWidget {
167170
class _StreamContentInputState extends State<_StreamContentInput> {
168171
late String _topicTextNormalized;
169172

173+
MentionAutocompleteView? model;
174+
175+
@override
176+
void didChangeDependencies() {
177+
super.didChangeDependencies();
178+
final store = PerAccountStoreWidget.of(context);
179+
if (model != null && model!.store == store) {
180+
// We already have a model, and it's for the right store.
181+
return;
182+
}
183+
// Otherwise, set up the model. Dispose of any old model.
184+
model?.dispose();
185+
_initModel(store);
186+
}
187+
188+
void _initModel(PerAccountStore store) {
189+
model = MentionAutocompleteView.init(store: store, narrow: const AllMessagesNarrow());
190+
model!.addListener(_modelChanged);
191+
}
192+
193+
void _modelChanged() {
194+
setState(() {
195+
// The actual state lives in the [MessageListView] model.
196+
// This method was called because that just changed.
197+
});
198+
}
199+
170200
_topicChanged() {
171201
setState(() {
172-
_topicTextNormalized = widget.topicController.textNormalized();
202+
model?.query = MentionAutocompleteQuery(widget.topicController.textNormalized());
173203
});
174204
}
175205

@@ -182,6 +212,7 @@ class _StreamContentInputState extends State<_StreamContentInput> {
182212

183213
@override
184214
void dispose() {
215+
print(model!.results.map((r) => (r as UserMentionAutocompleteResult).userId));
185216
widget.topicController.removeListener(_topicChanged);
186217
super.dispose();
187218
}

0 commit comments

Comments
 (0)