Skip to content

Commit

Permalink
Show empty view when list is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
KingWu committed Jan 13, 2019
1 parent 1247e23 commit 7f5be04
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 43 deletions.
94 changes: 57 additions & 37 deletions lib/app/ui/page/HomePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,50 +114,70 @@ class _HomePageState extends State<HomePage> {
return StreamBuilder(
stream: bloc.feedList,
builder: (context, snapshot) {
List<HomeListItem> 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<HomeListItem> 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<HomeListItem, num>(
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<HomeListItem, num>(
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);
}
);
}
);
}
}
}
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/generated/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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 => "評論";
Expand All @@ -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 => "コメント";
Expand Down
4 changes: 2 additions & 2 deletions res/values/strings_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"homeSearchHint": "Suche ...",
"homeRecommend": "Empfehlen",
"dialogLoading": "Wird geladen ...",
"detailRate": "Bemerkungen"

"detailRate": "Bemerkungen",
"homeEmptyList": "Keine Ergebnisse"
}
4 changes: 2 additions & 2 deletions res/values/strings_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"homeSearchHint": "Search ...",
"homeRecommend": "Recommend",
"dialogLoading": "Loading ...",
"detailRate": "Comments"

"detailRate": "Comments",
"homeEmptyList": "No results"
}
3 changes: 2 additions & 1 deletion res/values/strings_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"homeSearchHint": "検索 ...",
"homeRecommend": "おすすめ",
"dialogLoading": "読み込み中 ...",
"detailRate": "コメント"
"detailRate": "コメント",
"homeEmptyList": "結果なし"

}
4 changes: 3 additions & 1 deletion res/values/strings_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"homeSearchHint": "搜索 ...",
"homeRecommend": "推介",
"dialogLoading": "載入中 ...",
"detailRate": "評論"
"detailRate": "評論",
"homeEmptyList": "沒有結果"

}

0 comments on commit 7f5be04

Please sign in to comment.