2018-09-17 16:16:50 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2018-09-15 16:21:48 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2018-09-15 15:01:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2019-03-18 15:30:54 +00:00
|
|
|
import 'package:after_layout/after_layout.dart';
|
2021-06-04 09:34:25 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2019-03-18 15:30:54 +00:00
|
|
|
|
2018-09-27 15:55:56 +00:00
|
|
|
import 'package:vikunja_app/components/AddDialog.dart';
|
2018-09-22 20:56:16 +00:00
|
|
|
import 'package:vikunja_app/global.dart';
|
2019-03-11 20:29:15 +00:00
|
|
|
import 'package:vikunja_app/models/list.dart';
|
2018-09-22 20:56:16 +00:00
|
|
|
import 'package:vikunja_app/models/namespace.dart';
|
2019-03-16 13:29:00 +00:00
|
|
|
import 'package:vikunja_app/pages/list/list.dart';
|
2021-06-04 09:34:25 +00:00
|
|
|
import 'package:vikunja_app/stores/list_store.dart';
|
2018-09-15 15:01:45 +00:00
|
|
|
|
2019-03-16 13:29:00 +00:00
|
|
|
class NamespacePage extends StatefulWidget {
|
2018-09-17 16:16:50 +00:00
|
|
|
final Namespace namespace;
|
2019-03-14 21:27:13 +00:00
|
|
|
|
2019-03-16 13:29:00 +00:00
|
|
|
NamespacePage({this.namespace}) : super(key: Key(namespace.id.toString()));
|
2018-09-15 15:01:45 +00:00
|
|
|
|
2018-09-15 16:21:48 +00:00
|
|
|
@override
|
2019-03-16 13:29:00 +00:00
|
|
|
_NamespacePageState createState() => new _NamespacePageState();
|
2018-09-15 16:21:48 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 15:30:54 +00:00
|
|
|
class _NamespacePageState extends State<NamespacePage>
|
|
|
|
with AfterLayoutMixin<NamespacePage> {
|
2018-09-17 16:16:50 +00:00
|
|
|
List<TaskList> _lists = [];
|
2018-09-27 15:55:56 +00:00
|
|
|
bool _loading = true;
|
2018-09-15 15:22:28 +00:00
|
|
|
|
2019-03-18 15:30:54 +00:00
|
|
|
@override
|
|
|
|
void afterFirstLayout(BuildContext context) {
|
2021-03-19 15:13:38 +00:00
|
|
|
//_loadLists(); // NOTE: goes right after didChangeDependencies
|
2019-03-18 15:30:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 13:29:00 +00:00
|
|
|
/////
|
|
|
|
// This essentially shows the lists.
|
2018-09-15 15:01:45 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-09-17 16:16:50 +00:00
|
|
|
return Scaffold(
|
2018-09-27 15:55:56 +00:00
|
|
|
body: !this._loading
|
|
|
|
? RefreshIndicator(
|
2019-03-18 17:05:32 +00:00
|
|
|
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) {
|
2021-03-15 07:31:38 +00:00
|
|
|
_removeList(ls).then((_) => ScaffoldMessenger.of(context)
|
|
|
|
.showSnackBar(SnackBar(content: Text("${ls.title} removed"))));
|
2019-03-18 17:05:32 +00:00
|
|
|
},
|
|
|
|
))).toList(),
|
|
|
|
)
|
|
|
|
: Center(child: Text('This namespace is empty.')),
|
2019-03-18 15:30:54 +00:00
|
|
|
onRefresh: _loadLists,
|
2018-09-27 15:55:56 +00:00
|
|
|
)
|
|
|
|
: Center(child: CircularProgressIndicator()),
|
2019-03-15 06:52:50 +00:00
|
|
|
floatingActionButton: Builder(
|
|
|
|
builder: (context) => FloatingActionButton(
|
2019-03-15 22:14:37 +00:00
|
|
|
onPressed: () => _addListDialog(context),
|
|
|
|
child: const Icon(Icons.add))),
|
2018-09-15 16:21:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-18 17:05:32 +00:00
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
|
|
|
_loadLists();
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:16:50 +00:00
|
|
|
Future _removeList(TaskList list) {
|
|
|
|
return VikunjaGlobal.of(context)
|
|
|
|
.listService
|
|
|
|
.delete(list.id)
|
2019-03-18 15:30:54 +00:00
|
|
|
.then((_) => _loadLists());
|
2018-09-17 16:16:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 15:30:54 +00:00
|
|
|
Future<void> _loadLists() {
|
2021-06-04 09:34:25 +00:00
|
|
|
// FIXME: This is called even when the tasks on a list are loaded - which is not needed at all
|
2018-09-27 15:55:56 +00:00
|
|
|
return VikunjaGlobal.of(context)
|
2018-09-17 16:16:50 +00:00
|
|
|
.listService
|
|
|
|
.getByNamespace(widget.namespace.id)
|
2018-09-27 15:55:56 +00:00
|
|
|
.then((lists) => setState(() {
|
|
|
|
this._lists = lists;
|
|
|
|
this._loading = false;
|
|
|
|
}));
|
2018-09-17 16:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_openList(BuildContext context, TaskList list) {
|
2021-06-04 09:34:25 +00:00
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => ChangeNotifierProvider<ListProvider>(
|
|
|
|
create: (_) => new ListProvider(),
|
|
|
|
child: ListPage(
|
|
|
|
taskList: list,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// ListPage(taskList: list)
|
|
|
|
));
|
2018-09-17 16:16:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 06:52:50 +00:00
|
|
|
_addListDialog(BuildContext context) {
|
2018-09-17 16:16:50 +00:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
2018-09-27 15:55:56 +00:00
|
|
|
builder: (_) => AddDialog(
|
2019-03-15 06:52:50 +00:00
|
|
|
onAdd: (name) => _addList(name, context),
|
2018-09-27 15:55:56 +00:00
|
|
|
decoration: new InputDecoration(
|
|
|
|
labelText: 'List Name', hintText: 'eg. Shopping List')),
|
2018-09-17 16:16:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-15 06:52:50 +00:00
|
|
|
_addList(String name, BuildContext context) {
|
2018-09-17 16:16:50 +00:00
|
|
|
VikunjaGlobal.of(context)
|
2019-03-15 22:14:37 +00:00
|
|
|
.listService
|
|
|
|
.create(widget.namespace.id, TaskList(id: null, title: name, tasks: []))
|
|
|
|
.then((_) {
|
|
|
|
setState(() {});
|
2019-03-18 15:30:54 +00:00
|
|
|
_loadLists();
|
2021-03-15 07:31:38 +00:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
2019-03-15 22:14:37 +00:00
|
|
|
SnackBar(
|
|
|
|
content: Text('The list was successfully created!'),
|
|
|
|
),
|
|
|
|
);
|
2019-03-14 21:27:13 +00:00
|
|
|
});
|
2018-09-15 15:01:45 +00:00
|
|
|
}
|
|
|
|
}
|