Reformat code

Add "Add namespace" functionality
This commit is contained in:
Jonas Franz 2018-09-15 17:22:28 +02:00
parent 9acc0ff750
commit 7e681bd16b
No known key found for this signature in database
GPG Key ID: 506AEEBE80BEDECD
4 changed files with 83 additions and 99 deletions

View File

@ -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: <Widget>[
new Container(
child: new Text(
'Namespace: $namespace',
style: Theme.of(context).textTheme.title,
),
),
new Text('You\'ve selected a namespace!')
],
));
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
child: new Text(
'Namespace: $namespace',
style: Theme.of(context).textTheme.title,
),
),
new Text('You\'ve selected a namespace!')
],
));
}
}

View File

@ -14,4 +14,4 @@ class VikunjaApp extends StatelessWidget {
home: new HomePage(),
);
}
}
}

View File

@ -5,18 +5,14 @@ import 'package:fluttering_vikunja/fragments/placeholder.dart';
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() => new HomePageState();
}
class HomePageState extends State<HomePage> {
List<String> namespaces = [
"Jonas's namespace",
'Another namespace'
];
List<String> 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<HomePage> {
_addNamespace() {
var textController = new TextEditingController();
showDialog(context: context, child: new _SystemPadding(
child: new AlertDialog(
contentPadding: const EdgeInsets.all(4.0),
content: new Row(
children: <Widget>[
Expanded(
showDialog(
context: context,
child: new _SystemPadding(
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'
),
labelText: 'Namespace', hintText: 'eg. Family Namespace'),
controller: textController,
),
)
]),
actions: <Widget>[
new FlatButton(
child: const Text('CANCEL'),
onPressed: () => Navigator.pop(context),
),
)
]
),
actions: <Widget>[
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<Widget> drawerOptions = <Widget>[];
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: <Widget>[
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: <Widget>[
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);
}
}
}

View File

@ -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',
)
)
);
}
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',
),
));
}