@@ -99,11 +99,35 @@ class _TaskListState extends State<TaskList> {
99
99
return Expanded (
100
100
child: StreamBuilder <List <Task >>(
101
101
stream: objectbox.getTasks (),
102
- builder: (context, snapshot) => ListView .builder (
103
- shrinkWrap: true ,
104
- padding: const EdgeInsets .symmetric (horizontal: 20.0 ),
105
- itemCount: snapshot.hasData ? snapshot.data! .length : 0 ,
106
- itemBuilder: _itemBuilder (snapshot.data ?? []))));
102
+ builder: (context, snapshot) {
103
+ if (snapshot.hasError) {
104
+ // Print the stack trace and show the error message.
105
+ // An actual app would display a user-friendly error message
106
+ // and report the error behind the scenes.
107
+ debugPrintStack (stackTrace: snapshot.stackTrace);
108
+ return Column (
109
+ mainAxisAlignment: MainAxisAlignment .center,
110
+ children: [
111
+ const Icon (
112
+ Icons .error_outline,
113
+ color: Colors .red,
114
+ size: 60 ,
115
+ ),
116
+ Padding (
117
+ padding:
118
+ const EdgeInsets .only (top: 16 , left: 16 , right: 16 ),
119
+ child: Text ('Error: ${snapshot .error }' ),
120
+ ),
121
+ ],
122
+ );
123
+ } else {
124
+ return ListView .builder (
125
+ shrinkWrap: true ,
126
+ padding: const EdgeInsets .symmetric (horizontal: 20.0 ),
127
+ itemCount: snapshot.hasData ? snapshot.data! .length : 0 ,
128
+ itemBuilder: _itemBuilder (snapshot.data ?? []));
129
+ }
130
+ }));
107
131
}
108
132
}
109
133
0 commit comments