Fixed namespaces loading every time a widget was loaded
This commit is contained in:
parent
75f6608863
commit
4714247172
|
@ -12,7 +12,6 @@ class VikunjaApp extends StatelessWidget {
|
|||
final Widget home;
|
||||
|
||||
const VikunjaApp({Key key, this.home}) : super(key: key);
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new MaterialApp(
|
||||
|
|
|
@ -21,54 +21,12 @@ class HomePageState extends State<HomePage> {
|
|||
: null;
|
||||
int _selectedDrawerIndex = -1;
|
||||
bool _loading = true;
|
||||
|
||||
_getDrawerItemWidget(int pos) {
|
||||
if (pos == -1) {
|
||||
return new PlaceholderPage();
|
||||
}
|
||||
return new NamespacePage(namespace: _namespaces[pos]);
|
||||
}
|
||||
|
||||
_onSelectItem(int index) {
|
||||
setState(() => _selectedDrawerIndex = index);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
_addNamespaceDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AddDialog(
|
||||
onAdd: (name) => _addNamespace(name, context),
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Namespace', hintText: 'eg. Personal Namespace'),
|
||||
));
|
||||
}
|
||||
|
||||
_addNamespace(String name, BuildContext context) {
|
||||
VikunjaGlobal.of(context)
|
||||
.namespaceService
|
||||
.create(Namespace(id: null, name: name))
|
||||
.then((_) {
|
||||
_loadNamespaces();
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('The namespace was created successfully!'),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadNamespaces() {
|
||||
return VikunjaGlobal.of(context).namespaceService.getAll().then((result) {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_namespaces = result;
|
||||
});
|
||||
});
|
||||
}
|
||||
bool _namespacesLoaded = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_loadNamespaces();
|
||||
_loadNamespacesOnce();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -128,4 +86,54 @@ class HomePageState extends State<HomePage> {
|
|||
body: _getDrawerItemWidget(_selectedDrawerIndex),
|
||||
);
|
||||
}
|
||||
|
||||
_loadNamespacesOnce() {
|
||||
if(!_namespacesLoaded) {
|
||||
_loadNamespaces();
|
||||
_namespacesLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
_getDrawerItemWidget(int pos) {
|
||||
if (pos == -1) {
|
||||
return new PlaceholderPage();
|
||||
}
|
||||
return new NamespacePage(namespace: _namespaces[pos]);
|
||||
}
|
||||
|
||||
_onSelectItem(int index) {
|
||||
setState(() => _selectedDrawerIndex = index);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
_addNamespaceDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AddDialog(
|
||||
onAdd: (name) => _addNamespace(name, context),
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Namespace', hintText: 'eg. Personal Namespace'),
|
||||
));
|
||||
}
|
||||
|
||||
_addNamespace(String name, BuildContext context) {
|
||||
VikunjaGlobal.of(context)
|
||||
.namespaceService
|
||||
.create(Namespace(id: null, name: name))
|
||||
.then((_) {
|
||||
_loadNamespaces();
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('The namespace was created successfully!'),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadNamespaces() {
|
||||
return VikunjaGlobal.of(context).namespaceService.getAll().then((result) {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_namespaces = result;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user