From 7f5be04cea790b9512dd052285a6403fd1b484d0 Mon Sep 17 00:00:00 2001 From: King Wu Date: Sun, 13 Jan 2019 17:44:20 +0800 Subject: [PATCH] Show empty view when list is empty --- lib/app/ui/page/HomePage.dart | 94 +++++++++++++++++++++-------------- lib/generated/i18n.dart | 7 +++ res/values/strings_de.arb | 4 +- res/values/strings_en.arb | 4 +- res/values/strings_ja.arb | 3 +- res/values/strings_zh_TW.arb | 4 +- 6 files changed, 73 insertions(+), 43 deletions(-) diff --git a/lib/app/ui/page/HomePage.dart b/lib/app/ui/page/HomePage.dart index ab0fe67..cce5100 100644 --- a/lib/app/ui/page/HomePage.dart +++ b/lib/app/ui/page/HomePage.dart @@ -114,50 +114,70 @@ class _HomePageState extends State { return StreamBuilder( stream: bloc.feedList, builder: (context, snapshot) { - List feedList = snapshot.data; - return ListView.builder( - key: listViewKey, - scrollDirection: Axis.vertical, - itemCount: null != feedList ? feedList.length : 0, - itemBuilder: (context, index) { + + + switch(snapshot.connectionState){ + case ConnectionState.none: + case ConnectionState.waiting:{ + return Center( + child: Text(S.of(context).dialogLoading) + ); + } + case ConnectionState.done: + case ConnectionState.active:{ + + List feedList = snapshot.data; + if(0 == feedList.length){ + return Center( + child: Text(S.of(context).homeEmptyList) + ); + } + + return ListView.builder( + key: listViewKey, + scrollDirection: Axis.vertical, + itemCount: null != feedList ? feedList.length : 0, + itemBuilder: (context, index) { // Log.info('index : $index'); - HomeListItem listItem = feedList[index]; + HomeListItem listItem = feedList[index]; - if(null == _keys[listItem.getId()]){ - _keys[listItem.getId()] = ValueKey(listItem.getId()); - } + if(null == _keys[listItem.getId()]){ + _keys[listItem.getId()] = ValueKey(listItem.getId()); + } - var key = _keys[listItem.getId()]; + var key = _keys[listItem.getId()]; - if(HomeListType.TYPE_FEATURE == listItem.type){ - return Container( - key: key, - child: buildFeatureListItem(listItem), - ); - } + if(HomeListType.TYPE_FEATURE == listItem.type){ + return Container( + key: key, + child: buildFeatureListItem(listItem), + ); + } - bool isFeatureListItemExist = HomeListType.TYPE_FEATURE == feedList[0].type; - - return StreamListItem( - key: key, - initialData: listItem, - stream: bloc.noticeItemUpdate, - comparator: (HomeListItem listItem, num appId){ - if(HomeListType.TYPE_TOP_APP == listItem.type){ - TopAppListItem topAppListItem = listItem; - return topAppListItem.entry.trackId == appId; - } - - return false; - }, - builder: (BuildContext context, HomeListItem listItem){ + bool isFeatureListItemExist = HomeListType.TYPE_FEATURE == feedList[0].type; + + return StreamListItem( + key: key, + initialData: listItem, + stream: bloc.noticeItemUpdate, + comparator: (HomeListItem listItem, num appId){ + if(HomeListType.TYPE_TOP_APP == listItem.type){ + TopAppListItem topAppListItem = listItem; + return topAppListItem.entry.trackId == appId; + } + + return false; + }, + builder: (BuildContext context, HomeListItem listItem){ // Log.info('Updated : $index'); - return buildTopAppListItem(listItem, index, isFeatureListItemExist); - } - ); - } - ); + return buildTopAppListItem(listItem, index, isFeatureListItemExist); + } + ); + } + ); + } + } } ); } diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 4141f7f..45e14f8 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -22,6 +22,7 @@ class S implements WidgetsLocalizations { String get detailRate => "Comments"; String get dialogLoading => "Loading ..."; String get hello => "Hello"; + String get homeEmptyList => "No results"; String get homeRecommend => "Recommend"; String get homeSearchHint => "Search ..."; String get title => "Hello world App"; @@ -38,6 +39,8 @@ class $de extends S { @override String get dialogLoading => "Wird geladen ..."; @override + String get homeEmptyList => "Keine Ergebnisse"; + @override String get hello => "Hello De"; @override String get detailRate => "Bemerkungen"; @@ -58,6 +61,8 @@ class $zh_TW extends S { @override String get dialogLoading => "載入中 ..."; @override + String get homeEmptyList => "沒有結果"; + @override String get hello => "Hello"; @override String get detailRate => "評論"; @@ -78,6 +83,8 @@ class $ja extends S { @override String get dialogLoading => "読み込み中 ..."; @override + String get homeEmptyList => "結果なし"; + @override String get hello => "Hello"; @override String get detailRate => "コメント"; diff --git a/res/values/strings_de.arb b/res/values/strings_de.arb index c7f7207..208c4d6 100644 --- a/res/values/strings_de.arb +++ b/res/values/strings_de.arb @@ -4,6 +4,6 @@ "homeSearchHint": "Suche ...", "homeRecommend": "Empfehlen", "dialogLoading": "Wird geladen ...", - "detailRate": "Bemerkungen" - + "detailRate": "Bemerkungen", + "homeEmptyList": "Keine Ergebnisse" } \ No newline at end of file diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index e8f71af..22086c5 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -4,6 +4,6 @@ "homeSearchHint": "Search ...", "homeRecommend": "Recommend", "dialogLoading": "Loading ...", - "detailRate": "Comments" - + "detailRate": "Comments", + "homeEmptyList": "No results" } \ No newline at end of file diff --git a/res/values/strings_ja.arb b/res/values/strings_ja.arb index 8f0723f..48a38f3 100644 --- a/res/values/strings_ja.arb +++ b/res/values/strings_ja.arb @@ -4,6 +4,7 @@ "homeSearchHint": "検索 ...", "homeRecommend": "おすすめ", "dialogLoading": "読み込み中 ...", - "detailRate": "コメント" + "detailRate": "コメント", + "homeEmptyList": "結果なし" } \ No newline at end of file diff --git a/res/values/strings_zh_TW.arb b/res/values/strings_zh_TW.arb index 2f5cff5..15c5c4d 100644 --- a/res/values/strings_zh_TW.arb +++ b/res/values/strings_zh_TW.arb @@ -4,5 +4,7 @@ "homeSearchHint": "搜索 ...", "homeRecommend": "推介", "dialogLoading": "載入中 ...", - "detailRate": "評論" + "detailRate": "評論", + "homeEmptyList": "沒有結果" + } \ No newline at end of file