parent
cc25bba0c7
commit
67e47b03cd
|
@ -55,8 +55,10 @@ class _NamespaceFragmentState extends State<NamespaceFragment> {
|
|||
onRefresh: _updateLists,
|
||||
)
|
||||
: Center(child: CircularProgressIndicator()),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _addListDialog(), child: const Icon(Icons.add)),
|
||||
floatingActionButton: Builder(
|
||||
builder: (context) => FloatingActionButton(
|
||||
onPressed: () => _addListDialog(context), child: const Icon(Icons.add))
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -88,23 +90,28 @@ class _NamespaceFragmentState extends State<NamespaceFragment> {
|
|||
MaterialPageRoute(builder: (context) => ListPage(taskList: list)));
|
||||
}
|
||||
|
||||
_addListDialog() {
|
||||
_addListDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AddDialog(
|
||||
onAdd: _addList,
|
||||
onAdd: (name) => _addList(name, context),
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'List Name', hintText: 'eg. Shopping List')),
|
||||
);
|
||||
}
|
||||
|
||||
_addList(String name) {
|
||||
_addList(String name, BuildContext context) {
|
||||
VikunjaGlobal.of(context)
|
||||
.listService
|
||||
.create(widget.namespace.id, TaskList(id: null, title: name, tasks: []))
|
||||
.then((_) {
|
||||
setState(() {});
|
||||
_updateLists();
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('The list was successfully created!'),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,21 +36,26 @@ class HomePageState extends State<HomePage> {
|
|||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
_addNamespaceDialog() {
|
||||
_addNamespaceDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AddDialog(
|
||||
onAdd: _addNamespace,
|
||||
onAdd: (name) => _addNamespace(name, context),
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Namespace', hintText: 'eg. Personal Namespace'),
|
||||
));
|
||||
}
|
||||
|
||||
_addNamespace(String name) {
|
||||
_addNamespace(String name, BuildContext context) {
|
||||
VikunjaGlobal.of(context)
|
||||
.namespaceService
|
||||
.create(Namespace(id: null, name: name))
|
||||
.then((_) => _updateNamespaces());
|
||||
.then((_) {
|
||||
_updateNamespaces();
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('The namespace was created successfully!'),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _updateNamespaces() {
|
||||
|
@ -113,10 +118,12 @@ class HomePageState extends State<HomePage> {
|
|||
)),
|
||||
new Align(
|
||||
alignment: FractionalOffset.bottomCenter,
|
||||
child: new ListTile(
|
||||
leading: const Icon(Icons.add),
|
||||
title: const Text('Add namespace...'),
|
||||
onTap: () => _addNamespaceDialog(),
|
||||
child: Builder(
|
||||
builder: (context) => ListTile(
|
||||
leading: const Icon(Icons.add),
|
||||
title: const Text('Add namespace...'),
|
||||
onTap: () => _addNamespaceDialog(context),
|
||||
),
|
||||
),
|
||||
),
|
||||
])),
|
||||
|
|
|
@ -105,19 +105,17 @@ class _ListEditPageState extends State<ListEditPage> {
|
|||
VikunjaGlobal.of(context).listService.update(updatedList)
|
||||
.then((_) {
|
||||
setState(() => _loading = false);
|
||||
final scaffold = Scaffold.of(context);
|
||||
scaffold.showSnackBar(SnackBar(
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('The list was updated successfully!'),
|
||||
));
|
||||
})
|
||||
.catchError((err) {
|
||||
setState(() => _loading = false);
|
||||
final scaffold = Scaffold.of(context);
|
||||
scaffold.showSnackBar(
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Something went wrong: ' + err.toString()),
|
||||
action: SnackBarAction(
|
||||
label: 'CLOSE', onPressed: scaffold.hideCurrentSnackBar),
|
||||
label: 'CLOSE', onPressed: Scaffold.of(context).hideCurrentSnackBar),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ class _ListPageState extends State<ListPage> {
|
|||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_updateList();
|
||||
_loadList();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -59,12 +59,13 @@ class _ListPageState extends State<ListPage> {
|
|||
ListTile.divideTiles(context: context, tiles: _listTasks())
|
||||
.toList(),
|
||||
),
|
||||
onRefresh: _updateList,
|
||||
onRefresh: _loadList,
|
||||
)
|
||||
: Center(child: CircularProgressIndicator()),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _addItemDialog(), child: Icon(Icons.add)),
|
||||
);
|
||||
floatingActionButton: Builder(
|
||||
builder: (context) => FloatingActionButton(
|
||||
onPressed: () => _addItemDialog(context), child: Icon(Icons.add)),
|
||||
));
|
||||
}
|
||||
|
||||
List<Widget> _listTasks() {
|
||||
|
@ -84,7 +85,7 @@ class _ListPageState extends State<ListPage> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> _updateList() {
|
||||
Future<void> _loadList() {
|
||||
return VikunjaGlobal.of(context)
|
||||
.listService
|
||||
.get(widget.taskList.id)
|
||||
|
@ -96,16 +97,16 @@ class _ListPageState extends State<ListPage> {
|
|||
});
|
||||
}
|
||||
|
||||
_addItemDialog() {
|
||||
_addItemDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AddDialog(
|
||||
onAdd: _addItem,
|
||||
onAdd: (name) => _addItem(name, context),
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Task Name', hintText: 'eg. Milk')));
|
||||
}
|
||||
|
||||
_addItem(String name) {
|
||||
_addItem(String name, BuildContext context) {
|
||||
var globalState = VikunjaGlobal.of(context);
|
||||
var newTask =
|
||||
Task(id: null, text: name, owner: globalState.currentUser, done: false);
|
||||
|
@ -115,8 +116,11 @@ class _ListPageState extends State<ListPage> {
|
|||
_list.tasks.add(task);
|
||||
});
|
||||
}).then((_) {
|
||||
_updateList();
|
||||
_loadList();
|
||||
setState(() => _loadingTasks.remove(newTask));
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('The task was added successfully!'),
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue