@@ -34,9 +34,9 @@ class MyApp extends StatelessWidget {
34
34
@override
35
35
Widget build (BuildContext context) {
36
36
return MaterialApp (
37
- title: 'OB Example' ,
37
+ title: 'OB Example (sync) ' ,
38
38
theme: ThemeData (primarySwatch: Colors .blue),
39
- home: MyHomePage (title: 'OB Example' ),
39
+ home: MyHomePage (title: 'OB Example (sync) ' ),
40
40
);
41
41
}
42
42
}
@@ -64,23 +64,20 @@ class ViewModel {
64
64
_query = _box.query ().order (dateProp, flags: Order .descending).build ();
65
65
66
66
// TODO configure actual sync server address and authentication
67
+ // For configuration and docs, see objectbox/lib/src/sync.dart
67
68
// 10.0.2.2 is your host PC if an app is run in an Android emulator.
68
69
// 127.0.0.1 is your host PC if an app is run in an iOS simulator.
69
- // For other options, see objectbox/lib/src/sync.dart
70
+ final syncServerIp = Platform .isAndroid ? '10.0.2.2' : '127.0.0.1' ;
70
71
final syncClient =
71
- Sync .client (_store, 'ws://10.0.2.2 :9999' , SyncCredentials .none ());
72
+ Sync .client (_store, 'ws://$ syncServerIp :9999' , SyncCredentials .none ());
72
73
syncClient.start ();
73
74
}
74
75
75
76
void addNote (Note note) => _box.put (note);
76
77
77
78
void removeNote (Note note) => _box.remove (note.id);
78
79
79
- // Note: using query.findStream() and sync.client() in the same app is
80
- // currently not supported so this app is currently not working and only
81
- // servers as an example on how and when to start a sync client.
82
- // Stream<List<Note>> get queryStream => _query.findStream();
83
- Stream <List <Note >> get queryStream => Stream <List <Note >>.empty ();
80
+ Stream <List <Note >> get queryStream => _query.findStream ();
84
81
85
82
List <Note > get allNotes => _query.find ();
86
83
@@ -144,6 +141,8 @@ class _MyHomePageState extends State<MyHomePage> {
144
141
style: TextStyle (
145
142
fontSize: 15.0 ,
146
143
),
144
+ // Provide a Key for the integration test
145
+ key: Key ('list_item_${index }' ),
147
146
),
148
147
Padding (
149
148
padding: EdgeInsets .only (top: 5.0 ),
@@ -188,6 +187,8 @@ class _MyHomePageState extends State<MyHomePage> {
188
187
InputDecoration (hintText: 'Enter a new note' ),
189
188
controller: _noteInputController,
190
189
onSubmitted: (value) => _addNote (),
190
+ // Provide a Key for the integration test
191
+ key: Key ('input' ),
191
192
),
192
193
),
193
194
Padding (
@@ -220,6 +221,14 @@ class _MyHomePageState extends State<MyHomePage> {
220
221
itemBuilder: _itemBuilder (snapshot.data));
221
222
}))
222
223
]),
224
+ // We need a separate submit button because flutter_driver integration
225
+ // test doesn't support submitting a TextField using "enter" key.
226
+ // See https://github.com/flutter/flutter/issues/9383
227
+ floatingActionButton: FloatingActionButton (
228
+ key: Key ('submit' ),
229
+ onPressed: _addNote,
230
+ child: Icon (Icons .add),
231
+ ),
223
232
);
224
233
}
225
234
}
0 commit comments