2018-09-15 15:01:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2018-09-16 19:47:33 +00:00
|
|
|
import 'package:fluttering_vikunja/components/GravatarImage.dart';
|
2018-09-15 15:01:45 +00:00
|
|
|
import 'package:fluttering_vikunja/fragments/namespace.dart';
|
|
|
|
import 'package:fluttering_vikunja/fragments/placeholder.dart';
|
2018-09-16 19:47:33 +00:00
|
|
|
import 'package:fluttering_vikunja/global.dart';
|
2018-09-17 16:16:50 +00:00
|
|
|
import 'package:fluttering_vikunja/models/namespace.dart';
|
|
|
|
import 'package:fluttering_vikunja/models/task.dart';
|
2018-09-16 19:47:33 +00:00
|
|
|
import 'package:fluttering_vikunja/models/user.dart';
|
2018-09-15 15:01:45 +00:00
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => new HomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class HomePageState extends State<HomePage> {
|
2018-09-17 16:16:50 +00:00
|
|
|
List<Namespace> _namespaces = [];
|
|
|
|
Namespace get _currentNamespace =>
|
|
|
|
_selectedDrawerIndex >= 0 && _selectedDrawerIndex < _namespaces.length
|
|
|
|
? _namespaces[_selectedDrawerIndex]
|
|
|
|
: null;
|
2018-09-15 15:01:45 +00:00
|
|
|
int _selectedDrawerIndex = -1;
|
|
|
|
|
|
|
|
_getDrawerItemWidget(int pos) {
|
2018-09-15 15:22:28 +00:00
|
|
|
if (pos == -1) {
|
2018-09-15 15:01:45 +00:00
|
|
|
return new PlaceholderFragment();
|
|
|
|
}
|
2018-09-17 16:16:50 +00:00
|
|
|
return new NamespaceFragment(namespace: _namespaces[pos]);
|
2018-09-15 15:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_onSelectItem(int index) {
|
|
|
|
setState(() => _selectedDrawerIndex = index);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:16:50 +00:00
|
|
|
_addNamespaceDialog() {
|
2018-09-15 15:10:34 +00:00
|
|
|
var textController = new TextEditingController();
|
2018-09-15 15:22:28 +00:00
|
|
|
showDialog(
|
2018-09-16 19:47:33 +00:00
|
|
|
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: 'Namespace', hintText: 'eg. Family Namespace'),
|
|
|
|
controller: textController,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
actions: <Widget>[
|
|
|
|
new FlatButton(
|
|
|
|
child: const Text('CANCEL'),
|
|
|
|
onPressed: () => Navigator.pop(context),
|
2018-09-15 15:10:34 +00:00
|
|
|
),
|
2018-09-16 19:47:33 +00:00
|
|
|
new FlatButton(
|
|
|
|
child: const Text('ADD'),
|
|
|
|
onPressed: () {
|
2018-09-17 16:16:50 +00:00
|
|
|
if (textController.text.isNotEmpty) {
|
|
|
|
_addNamespace(textController.text);
|
|
|
|
}
|
2018-09-16 19:47:33 +00:00
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:16:50 +00:00
|
|
|
_addNamespace(String name) {
|
|
|
|
VikunjaGlobal.of(context)
|
|
|
|
.namespaceService
|
|
|
|
.create(Namespace(id: null, name: name))
|
|
|
|
.then((_) => _updateNamespaces());
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateNamespaces() {
|
|
|
|
VikunjaGlobal.of(context).namespaceService.getAll().then((result) {
|
|
|
|
setState(() {
|
|
|
|
_namespaces = result;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-16 19:47:33 +00:00
|
|
|
@override
|
2018-09-17 16:16:50 +00:00
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
|
|
|
_updateNamespaces();
|
2018-09-15 15:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-09-16 19:47:33 +00:00
|
|
|
var currentUser = VikunjaGlobal.of(context).currentUser;
|
2018-09-15 15:01:45 +00:00
|
|
|
List<Widget> drawerOptions = <Widget>[];
|
2018-09-17 16:16:50 +00:00
|
|
|
_namespaces
|
|
|
|
.asMap()
|
|
|
|
.forEach((i, namespace) => drawerOptions.add(new ListTile(
|
|
|
|
leading: const Icon(Icons.folder),
|
|
|
|
title: new Text(namespace.name),
|
|
|
|
selected: i == _selectedDrawerIndex,
|
|
|
|
onTap: () => _onSelectItem(i),
|
|
|
|
)));
|
2018-09-16 19:47:33 +00:00
|
|
|
|
2018-09-15 15:01:45 +00:00
|
|
|
return new Scaffold(
|
2018-09-17 16:16:50 +00:00
|
|
|
appBar: AppBar(title: new Text(_currentNamespace?.name ?? 'Vakunja')),
|
2018-09-15 15:01:45 +00:00
|
|
|
drawer: new Drawer(
|
2018-09-15 15:22:28 +00:00
|
|
|
child: new Column(children: <Widget>[
|
|
|
|
new UserAccountsDrawerHeader(
|
2018-09-16 19:47:33 +00:00
|
|
|
accountEmail: currentUser == null ? null : Text(currentUser.email),
|
|
|
|
accountName: currentUser == null ? null : Text(currentUser.username),
|
2018-09-16 19:47:53 +00:00
|
|
|
currentAccountPicture: currentUser == null
|
|
|
|
? null
|
|
|
|
: CircleAvatar(
|
|
|
|
backgroundImage: GravatarImageProvider(currentUser.username)),
|
2018-09-15 17:40:59 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
image: DecorationImage(
|
|
|
|
image: AssetImage("assets/graphics/hypnotize.png"),
|
|
|
|
repeat: ImageRepeat.repeat,
|
2018-09-16 19:47:33 +00:00
|
|
|
colorFilter: ColorFilter.mode(
|
|
|
|
Theme.of(context).primaryColor, BlendMode.multiply)),
|
2018-09-15 17:40:59 +00:00
|
|
|
),
|
2018-09-15 15:22:28 +00:00
|
|
|
),
|
|
|
|
new Expanded(
|
|
|
|
child: ListView(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
children:
|
|
|
|
ListTile.divideTiles(context: context, tiles: drawerOptions)
|
|
|
|
.toList())),
|
|
|
|
new Align(
|
|
|
|
alignment: FractionalOffset.bottomCenter,
|
|
|
|
child: new ListTile(
|
|
|
|
leading: const Icon(Icons.add),
|
|
|
|
title: const Text('Add namespace...'),
|
2018-09-17 16:16:50 +00:00
|
|
|
onTap: () => _addNamespaceDialog(),
|
2018-09-15 15:22:28 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
])),
|
2018-09-15 15:01:45 +00:00
|
|
|
body: _getDrawerItemWidget(_selectedDrawerIndex),
|
|
|
|
);
|
|
|
|
}
|
2018-09-15 15:10:34 +00:00
|
|
|
}
|