From fb3c6e78ba0d3677ac85ceb240f169f0c97dae4c Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 15 Sep 2018 17:22:28 +0200 Subject: [PATCH] Reformat code Add "Add namespace" functionality --- lib/fragments/namespace.dart | 24 +++---- lib/main.dart | 2 +- lib/pages/home_page.dart | 122 ++++++++++++++++------------------- lib/style.dart | 34 ++++------ 4 files changed, 83 insertions(+), 99 deletions(-) diff --git a/lib/fragments/namespace.dart b/lib/fragments/namespace.dart index 28ebaeb..0848e5d 100644 --- a/lib/fragments/namespace.dart +++ b/lib/fragments/namespace.dart @@ -4,21 +4,21 @@ class NamespaceFragment extends StatelessWidget { final String namespace; NamespaceFragment({this.namespace}); - + @override Widget build(BuildContext context) { return new Center( child: new Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Container( - child: new Text( - 'Namespace: $namespace', - style: Theme.of(context).textTheme.title, - ), - ), - new Text('You\'ve selected a namespace!') - ], - )); + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Container( + child: new Text( + 'Namespace: $namespace', + style: Theme.of(context).textTheme.title, + ), + ), + new Text('You\'ve selected a namespace!') + ], + )); } } diff --git a/lib/main.dart b/lib/main.dart index 10d3914..d3319d9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,4 +14,4 @@ class VikunjaApp extends StatelessWidget { home: new HomePage(), ); } -} \ No newline at end of file +} diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index f6e3409..182a606 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -5,18 +5,14 @@ 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' - ]; + List namespaces = ["Jonas's namespace", 'Another namespace']; int _selectedDrawerIndex = -1; _getDrawerItemWidget(int pos) { - if(pos == -1) { + if (pos == -1) { return new PlaceholderFragment(); } return new NamespaceFragment(namespace: namespaces[pos]); @@ -29,79 +25,75 @@ class HomePageState extends State { _addNamespace() { var textController = new TextEditingController(); - showDialog(context: context, child: new _SystemPadding( - child: new AlertDialog( - contentPadding: const EdgeInsets.all(4.0), - content: new Row( - children: [ - Expanded( + showDialog( + context: context, + child: new _SystemPadding( + 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' - ), + labelText: 'Namespace', hintText: 'eg. Family Namespace'), controller: textController, + ), + ) + ]), + actions: [ + new FlatButton( + child: const Text('CANCEL'), + onPressed: () => Navigator.pop(context), ), - ) - ] - ), - 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); + }, + ) + ], ), - new FlatButton( - child: const Text('ADD'), - onPressed: () { - 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), - )) - ); + 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]), + 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'), - ), - new Column( - children: ListTile.divideTiles(context: context, tiles: drawerOptions).toList() - ), - new Expanded( - child: new Align( - alignment: FractionalOffset.bottomCenter, - child: new ListTile( - leading: const Icon(Icons.add), - title: const Text('Add namespace...'), - onTap: () => _addNamespace(), - ), - ), - ), - ] - ) - ), + child: new Column(children: [ + new UserAccountsDrawerHeader( + accountEmail: const Text('jonas@try.vikunja.io'), + accountName: const Text('Jonas Franz'), + ), + 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), ); } @@ -120,4 +112,4 @@ class _SystemPadding extends StatelessWidget { duration: const Duration(milliseconds: 300), child: child); } -} \ No newline at end of file +} diff --git a/lib/style.dart b/lib/style.dart index fb7ce07..047173c 100644 --- a/lib/style.dart +++ b/lib/style.dart @@ -8,24 +8,16 @@ const vBlack = Color(0xFFFFFFFF); ThemeData buildVikunjaTheme() { var base = ThemeData.light(); return base.copyWith( - primaryColor: vBlue, - primaryColorLight: vBlueLight, - primaryColorDark: vBlueDark, - textTheme: base.textTheme.copyWith( - headline: base.textTheme.headline.copyWith( - fontFamily: 'Quicksand', - fontSize: 72.0, - ), - subhead: base.textTheme.subhead.copyWith( - fontFamily: 'Quicksand', - fontSize: 24.0, - ), - title: base.textTheme.title.copyWith( - fontFamily: 'Quicksand', - ), - body1: base.textTheme.body1.copyWith( - fontFamily: 'Quicksand', - ) - ) - ); -} \ No newline at end of file + primaryColor: vBlue, + primaryColorLight: vBlueLight, + primaryColorDark: vBlueDark, + textTheme: base.textTheme.copyWith( + headline: base.textTheme.headline.copyWith( + fontFamily: 'Quicksand', + fontSize: 72.0, + ), + title: base.textTheme.title.copyWith( + fontFamily: 'Quicksand', + ), + )); +}