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