@@ -4,7 +4,21 @@ import 'package:exercise/models/user.dart';
4
4
import 'package:flutter/material.dart' ;
5
5
import 'package:http/http.dart' as http;
6
6
7
- class Home extends StatelessWidget {
7
+ class Home extends StatefulWidget {
8
+ @override
9
+ _HomeState createState () => _HomeState ();
10
+ }
11
+
12
+ class _HomeState extends State <Home > {
13
+ final apiKey = "" ;
14
+ final _controller = TextEditingController ();
15
+
16
+ @override
17
+ void dispose () {
18
+ _controller.dispose ();
19
+ super .dispose ();
20
+ }
21
+
8
22
@override
9
23
Widget build (BuildContext context) {
10
24
return Scaffold (
@@ -41,7 +55,7 @@ class Home extends StatelessWidget {
41
55
future: _future (),
42
56
builder: (context, snapshot) {
43
57
if (snapshot.hasData) {
44
- return _listView (snapshot.data);
58
+ return _content (snapshot.data);
45
59
}
46
60
47
61
if (snapshot.hasError) {
@@ -65,9 +79,58 @@ class Home extends StatelessWidget {
65
79
);
66
80
}
67
81
82
+ Widget _content (List <User > users) {
83
+ return Padding (
84
+ padding: const EdgeInsets .all (8.0 ),
85
+ child: Column (
86
+ children: [
87
+ _filterByCity (),
88
+ Expanded (child: _listView (users)),
89
+ ],
90
+ ),
91
+ );
92
+ }
93
+
94
+ Widget _filterByCity () {
95
+ return Padding (
96
+ padding: const EdgeInsets .all (8.0 ),
97
+ child: Row (
98
+ children: [
99
+ Expanded (child: _textField ()),
100
+ _filterButton (),
101
+ ],
102
+ ),
103
+ );
104
+ }
105
+
106
+ Widget _textField () {
107
+ return TextField (
108
+ textCapitalization: TextCapitalization .words,
109
+ decoration: InputDecoration (
110
+ border: OutlineInputBorder (),
111
+ hintText: 'Filter By City' ,
112
+ ),
113
+ controller: _controller,
114
+ );
115
+ }
116
+
117
+ Widget _filterButton () {
118
+ return Padding (
119
+ padding: const EdgeInsets .only (left: 8.0 ),
120
+ child: RaisedButton (
121
+ onPressed: _onFilterButtonPressed,
122
+ child: const Text ("Filter" ),
123
+ ),
124
+ );
125
+ }
126
+
127
+ void _onFilterButtonPressed () {
128
+ print ("Button pressed" );
129
+ }
130
+
68
131
Widget _listView (List <User > users) {
69
132
return ListView .builder (
70
- padding : const EdgeInsets . all ( 8.0 ) ,
133
+ shrinkWrap : true ,
71
134
itemCount: users.length,
72
135
itemBuilder: (context, index) {
73
136
return _listItem (users[index]);
0 commit comments