-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.dart
43 lines (40 loc) · 1.23 KB
/
search.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
import 'package:flutter/material.dart';
import 'package:news_app/news_list_builder.dart';
import 'package:news_app/services/rss_feed.dart';
import 'package:webfeed/domain/rss_item.dart';
class Search extends StatefulWidget {
@override
_SearchState createState() => _SearchState();
}
class _SearchState extends State<Search> {
final TextEditingController _filter = new TextEditingController();
List<String> filters;
_SearchState() {
// _filter a listener ekleyerek Arama listesinin dinamik olması sağlanıyor
_filter.addListener(() {
setState(() {
if (_filter.text.isEmpty && filters != null) {
filters.clear();
} else {
filters = _filter.text.toLowerCase().split(" ");
}
});
});
}
@override
Widget build(BuildContext context) {
List<RssItem> result = Rss.searchRssItems(filters);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: TextField(
autofocus: true,
controller: _filter,
decoration: new InputDecoration(
prefixIcon: new Icon(Icons.search), hintText: 'Ara...'),
)),
body: NewsListBuilder(
items: result ?? [],
));
}
}