From 82783402426e26a8396bdecd0f55a9e2aac1a180 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 18 Mar 2019 17:05:32 +0000 Subject: [PATCH] Show a message if a list or namespace is empty (#29) --- lib/models/list.dart | 2 +- lib/pages/list/list.dart | 18 +++++---- lib/pages/namespace/namespace.dart | 60 +++++++++++++++++------------- pubspec.lock | 15 ++++++-- 4 files changed, 57 insertions(+), 38 deletions(-) diff --git a/lib/models/list.dart b/lib/models/list.dart index 38ef0af..cf9a5ad 100644 --- a/lib/models/list.dart +++ b/lib/models/list.dart @@ -25,7 +25,7 @@ class TaskList { title = json['title'], updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), created = DateTime.fromMillisecondsSinceEpoch(json['created']), - tasks = (json['tasks'] as List) + tasks = (json['tasks'] == null ? [] : json['tasks'] as List) ?.map((taskJson) => Task.fromJson(taskJson)) ?.toList(); diff --git a/lib/pages/list/list.dart b/lib/pages/list/list.dart index f0a3a4e..f963a2a 100644 --- a/lib/pages/list/list.dart +++ b/lib/pages/list/list.dart @@ -53,12 +53,14 @@ class _ListPageState extends State { ), body: !this._loading ? RefreshIndicator( - child: ListView( - padding: EdgeInsets.symmetric(vertical: 8.0), - children: ListTile.divideTiles( - context: context, tiles: _listTasks()) - .toList(), - ), + child: _list.tasks.length > 0 + ? ListView( + padding: EdgeInsets.symmetric(vertical: 8.0), + children: ListTile.divideTiles( + context: context, tiles: _listTasks()) + .toList(), + ) + : Center(child: Text('This list is empty.')), onRefresh: _loadList, ) : Center(child: CircularProgressIndicator()), @@ -89,10 +91,10 @@ class _ListPageState extends State { return VikunjaGlobal.of(context) .listService .get(widget.taskList.id) - .then((tasks) { + .then((list) { setState(() { _loading = false; - _list = tasks; + _list = list; }); }); } diff --git a/lib/pages/namespace/namespace.dart b/lib/pages/namespace/namespace.dart index 85b6f36..07f6f87 100644 --- a/lib/pages/namespace/namespace.dart +++ b/lib/pages/namespace/namespace.dart @@ -36,31 +36,35 @@ class _NamespacePageState extends State return Scaffold( body: !this._loading ? RefreshIndicator( - child: new ListView( - padding: EdgeInsets.symmetric(vertical: 8.0), - children: ListTile.divideTiles( - context: context, - tiles: _lists.map((ls) => Dismissible( - key: Key(ls.id.toString()), - direction: DismissDirection.startToEnd, - child: ListTile( - title: new Text(ls.title), - onTap: () => _openList(context, ls), - trailing: Icon(Icons.arrow_right), - ), - background: Container( - color: Colors.red, - child: const ListTile( - leading: Icon(Icons.delete, - color: Colors.white, size: 36.0)), - ), - onDismissed: (direction) { - _removeList(ls).then((_) => Scaffold.of(context) - .showSnackBar(SnackBar( - content: Text("${ls.title} removed")))); - }, - ))).toList(), - ), + child: _lists.length > 0 + ? new ListView( + padding: EdgeInsets.symmetric(vertical: 8.0), + children: ListTile.divideTiles( + context: context, + tiles: _lists.map((ls) => Dismissible( + key: Key(ls.id.toString()), + direction: DismissDirection.startToEnd, + child: ListTile( + title: new Text(ls.title), + onTap: () => _openList(context, ls), + trailing: Icon(Icons.arrow_right), + ), + background: Container( + color: Colors.red, + child: const ListTile( + leading: Icon(Icons.delete, + color: Colors.white, size: 36.0)), + ), + onDismissed: (direction) { + _removeList(ls).then((_) => Scaffold.of( + context) + .showSnackBar(SnackBar( + content: + Text("${ls.title} removed")))); + }, + ))).toList(), + ) + : Center(child: Text('This namespace is empty.')), onRefresh: _loadLists, ) : Center(child: CircularProgressIndicator()), @@ -71,6 +75,12 @@ class _NamespacePageState extends State ); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _loadLists(); + } + Future _removeList(TaskList list) { return VikunjaGlobal.of(context) .listService diff --git a/pubspec.lock b/pubspec.lock index f0ea579..3e86bc3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -146,6 +146,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" petitparser: dependency: transitive description: @@ -171,7 +178,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.4" stack_trace: dependency: transitive description: @@ -199,14 +206,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.2" typed_data: dependency: transitive description: @@ -236,4 +243,4 @@ packages: source: hosted version: "2.1.15" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.1.0 <3.0.0"