@@ -35,9 +35,9 @@ class MyApp extends StatelessWidget {
35
35
@override
36
36
Widget build (BuildContext context) {
37
37
return MaterialApp (
38
- title: 'OB Example' ,
38
+ title: 'OB Example (sync) ' ,
39
39
theme: ThemeData (primarySwatch: Colors .blue),
40
- home: MyHomePage (title: 'OB Example' ),
40
+ home: MyHomePage (title: 'OB Example (sync) ' ),
41
41
);
42
42
}
43
43
}
@@ -65,23 +65,20 @@ class ViewModel {
65
65
_query = _box.query ().order (dateProp, flags: Order .descending).build ();
66
66
67
67
// TODO configure actual sync server address and authentication
68
+ // For configuration and docs, see objectbox/lib/src/sync.dart
68
69
// 10.0.2.2 is your host PC if an app is run in an Android emulator.
69
70
// 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' ;
71
72
final syncClient =
72
- Sync .client (_store, 'ws://10.0.2.2 :9999' , SyncCredentials .none ());
73
+ Sync .client (_store, 'ws://$ syncServerIp :9999' , SyncCredentials .none ());
73
74
syncClient.start ();
74
75
}
75
76
76
77
void addNote (Note note) => _box.put (note);
77
78
78
79
void removeNote (Note note) => _box.remove (note.id);
79
80
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 ();
85
82
86
83
List <Note > get allNotes => _query.find ();
87
84
@@ -145,6 +142,8 @@ class _MyHomePageState extends State<MyHomePage> {
145
142
style: TextStyle (
146
143
fontSize: 15.0 ,
147
144
),
145
+ // Provide a Key for the integration test
146
+ key: Key ('list_item_${index }' ),
148
147
),
149
148
Padding (
150
149
padding: EdgeInsets .only (top: 5.0 ),
@@ -189,6 +188,8 @@ class _MyHomePageState extends State<MyHomePage> {
189
188
InputDecoration (hintText: 'Enter a new note' ),
190
189
controller: _noteInputController,
191
190
onSubmitted: (value) => _addNote (),
191
+ // Provide a Key for the integration test
192
+ key: Key ('input' ),
192
193
),
193
194
),
194
195
Padding (
@@ -221,6 +222,14 @@ class _MyHomePageState extends State<MyHomePage> {
221
222
itemBuilder: _itemBuilder (snapshot.data));
222
223
}))
223
224
]),
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
+ ),
224
233
);
225
234
}
226
235
}
0 commit comments