Skip to content

Commit 13281f5

Browse files
Move computations outside of setState in Flutter
1 parent 13f1938 commit 13281f5

File tree

1 file changed

+3
-2
lines changed
  • examples/flutter/objectbox_demo_desktop/lib

1 file changed

+3
-2
lines changed

examples/flutter/objectbox_demo_desktop/lib/main.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ class _MyHomePageState extends State<MyHomePage> {
5151
int _lastPutId;
5252

5353
void _testGet() {
54+
final Note fetchedNote = _box.get(_lastPutId);
5455
setState(() {
5556
if(_lastPutId == null) {
5657
_status += "cannot get, as nothing was put in this session yet\n";
5758
return;
5859
}
59-
_status += "fetched note: ${_box.get(_lastPutId)}\n";
60+
_status += "fetched note: $fetchedNote\n";
6061
});
6162
}
6263

6364
void _testPut() {
65+
_lastPutId = _box.put(Note.construct("Hello"));
6466
setState(() {
65-
_lastPutId = _box.put(Note.construct("Hello"));
6667
_status += "put new note with id $_lastPutId\n";
6768
});
6869
}

0 commit comments

Comments
 (0)