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';
|
2018-09-22 20:56:16 +00:00
|
|
|
import 'package:vikunja_app/global.dart';
|
|
|
|
import 'package:vikunja_app/models/namespace.dart';
|
|
|
|
import 'package:vikunja_app/models/task.dart';
|
|
|
|
import 'package:vikunja_app/pages/list_page.dart';
|
2018-09-15 15:01:45 +00:00
|
|
|
|
2018-09-15 16:21:48 +00:00
|
|
|
class NamespaceFragment extends StatefulWidget {
|
2018-09-17 16:16:50 +00:00
|
|
|
final Namespace namespace;
|
|
|
|
NamespaceFragment({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
|
|
|
|
_NamespaceFragmentState createState() => new _NamespaceFragmentState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NamespaceFragmentState extends State<NamespaceFragment> {
|
2018-09-17 16:16:50 +00:00
|
|
|
List<TaskList> _lists = [];
|
2018-09-15 15:22:28 +00:00
|
|
|
|
2018-09-15 15:01:45 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-09-17 16:16:50 +00:00
|
|
|
return Scaffold(
|
|
|
|
body: 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(),
|
|
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: () => _addListDialog(), child: const Icon(Icons.add)),
|
2018-09-15 16:21:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:16:50 +00:00
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
|
|
|
_updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _removeList(TaskList list) {
|
|
|
|
return VikunjaGlobal.of(context)
|
|
|
|
.listService
|
|
|
|
.delete(list.id)
|
|
|
|
.then((_) => _updateLists());
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateLists() {
|
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.listService
|
|
|
|
.getByNamespace(widget.namespace.id)
|
|
|
|
.then((lists) => setState(() => this._lists = lists));
|
|
|
|
}
|
|
|
|
|
|
|
|
_openList(BuildContext context, TaskList list) {
|
2018-09-15 16:21:48 +00:00
|
|
|
Navigator.of(context).push(
|
2018-09-17 16:16:50 +00:00
|
|
|
MaterialPageRoute(builder: (context) => ListPage(taskList: list)));
|
|
|
|
}
|
|
|
|
|
|
|
|
_addListDialog() {
|
|
|
|
var textController = new TextEditingController();
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
child: new AlertDialog(
|
|
|
|
contentPadding: const EdgeInsets.all(16.0),
|
|
|
|
content: new Row(children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: new TextField(
|
|
|
|
autofocus: true,
|
|
|
|
decoration: new InputDecoration(
|
|
|
|
labelText: 'List Name', hintText: 'eg. Shopping List'),
|
|
|
|
controller: textController,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
actions: <Widget>[
|
|
|
|
new FlatButton(
|
|
|
|
child: const Text('CANCEL'),
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
),
|
|
|
|
new FlatButton(
|
|
|
|
child: const Text('ADD'),
|
|
|
|
onPressed: () {
|
|
|
|
if (textController.text.isNotEmpty) {
|
|
|
|
_addList(textController.text);
|
|
|
|
}
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_addList(String name) {
|
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.listService
|
|
|
|
.create(widget.namespace.id, TaskList(id: null, title: name, tasks: []))
|
|
|
|
.then((_) => setState(() {}));
|
2018-09-15 15:01:45 +00:00
|
|
|
}
|
|
|
|
}
|