Skip to content

Commit 2c81509

Browse files
committed
sync example update
1 parent e5dc293 commit 2c81509

File tree

1 file changed

+18
-9
lines changed
  • objectbox/example/flutter/objectbox_demo_sync/lib

1 file changed

+18
-9
lines changed

objectbox/example/flutter/objectbox_demo_sync/lib/main.dart

+18-9
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class MyApp extends StatelessWidget {
3535
@override
3636
Widget build(BuildContext context) {
3737
return MaterialApp(
38-
title: 'OB Example',
38+
title: 'OB Example (sync)',
3939
theme: ThemeData(primarySwatch: Colors.blue),
40-
home: MyHomePage(title: 'OB Example'),
40+
home: MyHomePage(title: 'OB Example (sync)'),
4141
);
4242
}
4343
}
@@ -65,23 +65,20 @@ class ViewModel {
6565
_query = _box.query().order(dateProp, flags: Order.descending).build();
6666

6767
// TODO configure actual sync server address and authentication
68+
// For configuration and docs, see objectbox/lib/src/sync.dart
6869
// 10.0.2.2 is your host PC if an app is run in an Android emulator.
6970
// 127.0.0.1 is your host PC if an app is run in an iOS simulator.
70-
// For other options, see objectbox/lib/src/sync.dart
71+
final syncServerIp = Platform.isAndroid ? '10.0.2.2' : '127.0.0.1';
7172
final syncClient =
72-
Sync.client(_store, 'ws://10.0.2.2:9999', SyncCredentials.none());
73+
Sync.client(_store, 'ws://$syncServerIp:9999', SyncCredentials.none());
7374
syncClient.start();
7475
}
7576

7677
void addNote(Note note) => _box.put(note);
7778

7879
void removeNote(Note note) => _box.remove(note.id);
7980

80-
// Note: using query.findStream() and sync.client() in the same app is
81-
// currently not supported so this app is currently not working and only
82-
// servers as an example on how and when to start a sync client.
83-
// Stream<List<Note>> get queryStream => _query.findStream();
84-
Stream<List<Note>> get queryStream => Stream<List<Note>>.empty();
81+
Stream<List<Note>> get queryStream => _query.findStream();
8582

8683
List<Note> get allNotes => _query.find();
8784

@@ -145,6 +142,8 @@ class _MyHomePageState extends State<MyHomePage> {
145142
style: TextStyle(
146143
fontSize: 15.0,
147144
),
145+
// Provide a Key for the integration test
146+
key: Key('list_item_${index}'),
148147
),
149148
Padding(
150149
padding: EdgeInsets.only(top: 5.0),
@@ -189,6 +188,8 @@ class _MyHomePageState extends State<MyHomePage> {
189188
InputDecoration(hintText: 'Enter a new note'),
190189
controller: _noteInputController,
191190
onSubmitted: (value) => _addNote(),
191+
// Provide a Key for the integration test
192+
key: Key('input'),
192193
),
193194
),
194195
Padding(
@@ -221,6 +222,14 @@ class _MyHomePageState extends State<MyHomePage> {
221222
itemBuilder: _itemBuilder(snapshot.data));
222223
}))
223224
]),
225+
// We need a separate submit button because flutter_driver integration
226+
// test doesn't support submitting a TextField using "enter" key.
227+
// See https://github.com/flutter/flutter/issues/9383
228+
floatingActionButton: FloatingActionButton(
229+
key: Key('submit'),
230+
onPressed: _addNote,
231+
child: Icon(Icons.add),
232+
),
224233
);
225234
}
226235
}

0 commit comments

Comments
 (0)