Show a message if a list or namespace is empty (#29)
continuous-integration/drone/push Build is passing Details

This commit is contained in:
konrad 2019-03-18 17:05:32 +00:00 committed by Gitea
parent 2121b831a0
commit 8278340242
4 changed files with 57 additions and 38 deletions

View File

@ -25,7 +25,7 @@ class TaskList {
title = json['title'],
updated = DateTime.fromMillisecondsSinceEpoch(json['updated']),
created = DateTime.fromMillisecondsSinceEpoch(json['created']),
tasks = (json['tasks'] as List<dynamic>)
tasks = (json['tasks'] == null ? [] : json['tasks'] as List<dynamic>)
?.map((taskJson) => Task.fromJson(taskJson))
?.toList();

View File

@ -53,12 +53,14 @@ class _ListPageState extends State<ListPage> {
),
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<ListPage> {
return VikunjaGlobal.of(context)
.listService
.get(widget.taskList.id)
.then((tasks) {
.then((list) {
setState(() {
_loading = false;
_list = tasks;
_list = list;
});
});
}

View File

@ -36,31 +36,35 @@ class _NamespacePageState extends State<NamespacePage>
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<NamespacePage>
);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadLists();
}
Future _removeList(TaskList list) {
return VikunjaGlobal.of(context)
.listService

View File

@ -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"