Skip to content

Commit e1c909f

Browse files
committed
Add NoResultCard, fixed #10
1 parent e3f8999 commit e1c909f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/search_data_source.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class SearchResult {
5050
: result.image.contextLink.hashCode;
5151
}
5252

53+
/// A wrapper class to generate search request. To make caching possible.
54+
class SearchRequest {}
55+
5356
class Promotion {
5457
final customsearch.Promotion promotion;
5558

lib/search_result_page.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,22 @@ class WebSearchResultCard extends StatelessWidget {
163163
}
164164
}
165165

166+
class NoResultCard extends StatelessWidget {
167+
@override
168+
Widget build(BuildContext context) {
169+
return new ListTile(
170+
title: new Text('No Result.'),
171+
);
172+
}
173+
}
174+
166175
enum SearchType { web, image }
167176
enum WebSearchLayout { simple, CSE }
168177

169178
class CustomSearchSearchDelegate extends SearchDelegate<SearchResult> {
170179
SearchDataSource dataSource;
171-
AutoCompleteDataSource autoCompleteDataSource = CommonEnglishWordAutoCompleteDataSource();
180+
AutoCompleteDataSource autoCompleteDataSource =
181+
CommonEnglishWordAutoCompleteDataSource();
172182
SearchType searchType;
173183

174184
CustomSearchSearchDelegate(
@@ -265,6 +275,15 @@ class CustomSearchSearchDelegate extends SearchDelegate<SearchResult> {
265275
return Text('Awaiting result...');
266276
case ConnectionState.done:
267277
if (snapshot.hasError) return Text('Error: ${snapshot.error}');
278+
if (snapshot.data.searchResults.isEmpty) {
279+
return GridView.count(
280+
crossAxisCount: 1,
281+
mainAxisSpacing: 4.0,
282+
crossAxisSpacing: 4.0,
283+
padding: const EdgeInsets.all(4.0),
284+
children: [new NoResultCard()],
285+
);
286+
}
268287
switch (this.searchType) {
269288
case SearchType.image:
270289
return GridView.count(

0 commit comments

Comments
 (0)