import 'package:flutter/material.dart'; import 'package:fluttering_vikunja/fragments/namespace.dart'; import 'package:fluttering_vikunja/fragments/placeholder.dart'; class HomePage extends StatefulWidget { @override State createState() => new HomePageState(); } class HomePageState extends State { List namespaces = ["Jonas's namespace", 'Another namespace']; int _selectedDrawerIndex = -1; _getDrawerItemWidget(int pos) { if (pos == -1) { return new PlaceholderFragment(); } return new NamespaceFragment(namespace: namespaces[pos]); } _onSelectItem(int index) { setState(() => _selectedDrawerIndex = index); Navigator.of(context).pop(); } _addNamespace() { var textController = new TextEditingController(); showDialog( context: context, child: new AlertDialog( contentPadding: const EdgeInsets.all(16.0), content: new Row(children: [ Expanded( child: new TextField( autofocus: true, decoration: new InputDecoration( labelText: 'Namespace', hintText: 'eg. Family Namespace'), controller: textController, ), ) ]), actions: [ new FlatButton( child: const Text('CANCEL'), onPressed: () => Navigator.pop(context), ), new FlatButton( child: const Text('ADD'), onPressed: () { if (textController.text.isNotEmpty) setState(() => namespaces.add(textController.text)); Navigator.pop(context); }, ) ], ), ); } @override Widget build(BuildContext context) { List drawerOptions = []; namespaces.asMap().forEach((i, namespace) => drawerOptions.add(new ListTile( leading: const Icon(Icons.folder), title: new Text(namespace), selected: i == _selectedDrawerIndex, onTap: () => _onSelectItem(i), ))); return new Scaffold( appBar: AppBar( title: new Text(_selectedDrawerIndex == -1 ? 'Vakunja' : namespaces[_selectedDrawerIndex]), ), drawer: new Drawer( child: new Column(children: [ new UserAccountsDrawerHeader( accountEmail: const Text('jonas@try.vikunja.io'), accountName: const Text('Jonas Franz'), decoration: BoxDecoration( image: DecorationImage( image: AssetImage("assets/graphics/hypnotize.png"), repeat: ImageRepeat.repeat, colorFilter: ColorFilter.mode(Theme.of(context).primaryColor, BlendMode.multiply) ), ), ), 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...'), onTap: () => _addNamespace(), ), ), ])), body: _getDrawerItemWidget(_selectedDrawerIndex), ); } }