Skip to content

Commit ac36c44

Browse files
committed
Add filter UI
1 parent 41922fc commit ac36c44

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

lib/pages/home.dart

+66-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ import 'package:exercise/models/user.dart';
44
import 'package:flutter/material.dart';
55
import 'package:http/http.dart' as http;
66

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+
822
@override
923
Widget build(BuildContext context) {
1024
return Scaffold(
@@ -41,7 +55,7 @@ class Home extends StatelessWidget {
4155
future: _future(),
4256
builder: (context, snapshot) {
4357
if (snapshot.hasData) {
44-
return _listView(snapshot.data);
58+
return _content(snapshot.data);
4559
}
4660

4761
if (snapshot.hasError) {
@@ -65,9 +79,58 @@ class Home extends StatelessWidget {
6579
);
6680
}
6781

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+
68131
Widget _listView(List<User> users) {
69132
return ListView.builder(
70-
padding: const EdgeInsets.all(8.0),
133+
shrinkWrap: true,
71134
itemCount: users.length,
72135
itemBuilder: (context, index) {
73136
return _listItem(users[index]);

0 commit comments

Comments
 (0)