-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsearch_on_backend.dart
80 lines (74 loc) · 2.26 KB
/
search_on_backend.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'package:flutter/material.dart';
import 'package:rx_dart_samples/widgets/no_items_found.dart';
import 'package:rx_dart_samples/widgets/stream_error_widget.dart';
import 'package:rx_dart_samples/widgets/stream_loading_widget.dart';
import 'bloc.dart';
class SearchOnBackend extends StatefulWidget {
@override
_SearchOnBackendState createState() => _SearchOnBackendState();
}
class _SearchOnBackendState extends State<SearchOnBackend> {
final _bloc = Bloc();
@override
void initState() {
super.initState();
//_bloc.init();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Search: On Backend"),
),
body: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(12),
child: TextField(
controller: _bloc.textController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(14),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
hintText: 'Search with post id...',
prefixIcon: Icon(Icons.search),
),
),
),
Expanded(
child: StreamBuilder<List?>(
stream: _bloc.dataStream,
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
return ListView(
children: <Widget>[
if (snapshot.data!.isNotEmpty)
...snapshot.data!.map(
(item) => ListTile(
title: Text(item),
),
)
else
NoItemsFound()
],
);
} else if (snapshot.hasError) {
return StreamErrorWidget(snapshot.error);
} else {
return StreamLoadingWidget();
}
},
),
),
],
),
);
}
@override
void dispose() {
_bloc.dispose();
super.dispose();
}
}