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'], title = json['title'],
updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), updated = DateTime.fromMillisecondsSinceEpoch(json['updated']),
created = DateTime.fromMillisecondsSinceEpoch(json['created']), 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)) ?.map((taskJson) => Task.fromJson(taskJson))
?.toList(); ?.toList();

View File

@ -53,12 +53,14 @@ class _ListPageState extends State<ListPage> {
), ),
body: !this._loading body: !this._loading
? RefreshIndicator( ? RefreshIndicator(
child: ListView( child: _list.tasks.length > 0
padding: EdgeInsets.symmetric(vertical: 8.0), ? ListView(
children: ListTile.divideTiles( padding: EdgeInsets.symmetric(vertical: 8.0),
context: context, tiles: _listTasks()) children: ListTile.divideTiles(
.toList(), context: context, tiles: _listTasks())
), .toList(),
)
: Center(child: Text('This list is empty.')),
onRefresh: _loadList, onRefresh: _loadList,
) )
: Center(child: CircularProgressIndicator()), : Center(child: CircularProgressIndicator()),
@ -89,10 +91,10 @@ class _ListPageState extends State<ListPage> {
return VikunjaGlobal.of(context) return VikunjaGlobal.of(context)
.listService .listService
.get(widget.taskList.id) .get(widget.taskList.id)
.then((tasks) { .then((list) {
setState(() { setState(() {
_loading = false; _loading = false;
_list = tasks; _list = list;
}); });
}); });
} }

View File

@ -36,31 +36,35 @@ class _NamespacePageState extends State<NamespacePage>
return Scaffold( return Scaffold(
body: !this._loading body: !this._loading
? RefreshIndicator( ? RefreshIndicator(
child: new ListView( child: _lists.length > 0
padding: EdgeInsets.symmetric(vertical: 8.0), ? new ListView(
children: ListTile.divideTiles( padding: EdgeInsets.symmetric(vertical: 8.0),
context: context, children: ListTile.divideTiles(
tiles: _lists.map((ls) => Dismissible( context: context,
key: Key(ls.id.toString()), tiles: _lists.map((ls) => Dismissible(
direction: DismissDirection.startToEnd, key: Key(ls.id.toString()),
child: ListTile( direction: DismissDirection.startToEnd,
title: new Text(ls.title), child: ListTile(
onTap: () => _openList(context, ls), title: new Text(ls.title),
trailing: Icon(Icons.arrow_right), onTap: () => _openList(context, ls),
), trailing: Icon(Icons.arrow_right),
background: Container( ),
color: Colors.red, background: Container(
child: const ListTile( color: Colors.red,
leading: Icon(Icons.delete, child: const ListTile(
color: Colors.white, size: 36.0)), leading: Icon(Icons.delete,
), color: Colors.white, size: 36.0)),
onDismissed: (direction) { ),
_removeList(ls).then((_) => Scaffold.of(context) onDismissed: (direction) {
.showSnackBar(SnackBar( _removeList(ls).then((_) => Scaffold.of(
content: Text("${ls.title} removed")))); context)
}, .showSnackBar(SnackBar(
))).toList(), content:
), Text("${ls.title} removed"))));
},
))).toList(),
)
: Center(child: Text('This namespace is empty.')),
onRefresh: _loadLists, onRefresh: _loadLists,
) )
: Center(child: CircularProgressIndicator()), : Center(child: CircularProgressIndicator()),
@ -71,6 +75,12 @@ class _NamespacePageState extends State<NamespacePage>
); );
} }
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadLists();
}
Future _removeList(TaskList list) { Future _removeList(TaskList list) {
return VikunjaGlobal.of(context) return VikunjaGlobal.of(context)
.listService .listService

View File

@ -146,6 +146,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.2" version: "1.6.2"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -171,7 +178,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.4.1" version: "1.5.4"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -199,14 +206,14 @@ packages:
name: term_glyph name: term_glyph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" version: "1.1.0"
test_api: test_api:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.1" version: "0.2.2"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
@ -236,4 +243,4 @@ packages:
source: hosted source: hosted
version: "2.1.15" version: "2.1.15"
sdks: sdks:
dart: ">=2.0.0 <3.0.0" dart: ">=2.1.0 <3.0.0"