1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-02 18:49:47 +00:00

added bottom navigation bar

This commit is contained in:
Benimautner 2023-05-14 01:28:30 +02:00
parent 882bf55009
commit 8a499960c1
3 changed files with 153 additions and 91 deletions

View File

@ -12,6 +12,7 @@ import 'package:vikunja_app/pages/namespace/namespace_edit.dart';
import 'package:vikunja_app/pages/landing_page.dart';
import 'package:vikunja_app/global.dart';
import 'package:vikunja_app/models/namespace.dart';
import 'package:vikunja_app/pages/namespace/overview.dart';
import 'package:vikunja_app/pages/settings.dart';
import 'package:vikunja_app/stores/list_store.dart';
@ -20,45 +21,13 @@ class HomePage extends StatefulWidget {
State<StatefulWidget> createState() => HomePageState();
}
class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
List<Namespace> _namespaces = [];
Namespace? get _currentNamespace =>
_selectedDrawerIndex >= 0 && _selectedDrawerIndex < _namespaces.length
? _namespaces[_selectedDrawerIndex]
: null;
int _selectedDrawerIndex = -1, _previousDrawerIndex = -1;
class HomePageState extends State<HomePage> {
int _selectedDrawerIndex = 0, _previousDrawerIndex = 0;
bool _loading = true;
bool _showUserDetails = false;
Widget? drawerItem;
@override
void afterFirstLayout(BuildContext context) {
_loadNamespaces();
}
Widget _namespacesWidget() {
List<Widget> namespacesList = <Widget>[];
_namespaces
.asMap()
.forEach((i, namespace) => namespacesList.add(new ListTile(
leading: const Icon(Icons.folder),
title: new Text(namespace.title),
selected: i == _selectedDrawerIndex,
onTap: () => _onSelectItem(i),
)));
return this._loading
? Center(child: CircularProgressIndicator())
: RefreshIndicator(
child: ListView(
padding: EdgeInsets.zero,
children: ListTile.divideTiles(
context: context, tiles: namespacesList)
.toList()),
onRefresh: _loadNamespaces,
);
}
Widget _userDetailsWidget(BuildContext context) {
return ListView(padding: EdgeInsets.zero, children: <Widget>[
@ -85,6 +54,12 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
]);
}
List<BottomNavigationBarItem> navbarItems = [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
BottomNavigationBarItem(icon: Icon(Icons.list), label: "Namespaces"),
BottomNavigationBarItem(icon: Icon(Icons.settings), label: "Settings"),
];
@override
Widget build(BuildContext context) {
final currentUser = VikunjaGlobal.of(context).currentUser;
@ -92,9 +67,18 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
drawerItem = _getDrawerItemWidget(_selectedDrawerIndex);
return new Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: navbarItems,
currentIndex: _selectedDrawerIndex,
onTap: (index) {
setState(() {
_selectedDrawerIndex = index;
});
},
),
appBar: AppBar(
title: new Text(_currentNamespace?.title ?? 'Vikunja'),
actions: _currentNamespace == null
title: new Text(navbarItems[_selectedDrawerIndex].label ?? "Vikunja"),
/*actions: _currentNamespace == null
? null
: <Widget>[
IconButton(
@ -105,17 +89,13 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
builder: (context) => NamespaceEditPage(
namespace: _currentNamespace!,
))).whenComplete(() => _loadNamespaces()))
],
],*/
),
drawer: Drawer(
child: Column(children: <Widget>[
UserAccountsDrawerHeader(
accountName: currentUser != null
? Text(currentUser.username)
: null,
accountEmail: currentUser != null
? Text(currentUser.name)
: null,
accountName: currentUser != null ? Text(currentUser.username) : null,
accountEmail: currentUser != null ? Text(currentUser.name) : null,
onDetailsPressed: () {
setState(() {
_showUserDetails = !_showUserDetails;
@ -134,11 +114,9 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
Theme.of(context).primaryColor, BlendMode.multiply)),
),
),
Builder(
/*Builder(
builder: (BuildContext context) => Expanded(
child: _showUserDetails
? _userDetailsWidget(context)
: _namespacesWidget())),
child: _userDetailsWidget(context))),
Align(
alignment: FractionalOffset.bottomLeft,
child: Builder(
@ -160,7 +138,7 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
onTap: () => _addNamespaceDialog(context),
),
),
),
),*/
])),
body: drawerItem,
);
@ -168,6 +146,19 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
_getDrawerItemWidget(int pos, {bool forceReload = false}) {
_previousDrawerIndex = pos;
switch (pos) {
case 0:
return ChangeNotifierProvider<ListProvider>(
create: (_) => new ListProvider(),
child: forceReload ? LandingPage(key: UniqueKey()) : LandingPage(),
);
case 1:
return NamespaceOverviewPage();
case 2:
return SettingsPage();
}
return null;
if (pos == -1) {
//return forceReload
// ? new LandingPage(key: UniqueKey())
@ -178,49 +169,9 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
child: forceReload ? LandingPage(key: UniqueKey()) : LandingPage(),
);
}
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) {
final currentUser = VikunjaGlobal.of(context).currentUser;
if (currentUser == null) {
return;
}
VikunjaGlobal.of(context)
.namespaceService
.create(Namespace(title: name, owner: currentUser))
.then((_) {
_loadNamespaces();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('The namespace was created successfully!'),
));
}).catchError((error) => showDialog(
context: context, builder: (context) => ErrorDialog(error: error)));
}
Future<void> _loadNamespaces() {
return VikunjaGlobal.of(context).namespaceService.getAll().then((result) {
setState(() {
_loading = false;
if(result != null)
_namespaces = result;
});
});
}
}

View File

@ -0,0 +1,114 @@
import 'package:after_layout/after_layout.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../components/AddDialog.dart';
import '../../components/ErrorDialog.dart';
import '../../global.dart';
import '../../models/namespace.dart';
import 'namespace.dart';
class NamespaceOverviewPage extends StatefulWidget {
@override
_NamespaceOverviewPageState createState() =>
new _NamespaceOverviewPageState();
}
class _NamespaceOverviewPageState extends State<NamespaceOverviewPage>
with AfterLayoutMixin<NamespaceOverviewPage> {
List<Namespace> _namespaces = [];
int _selectedDrawerIndex = -2, _previousDrawerIndex = -2;
bool _loading = true;
Namespace? get _currentNamespace =>
_selectedDrawerIndex >= -1 && _selectedDrawerIndex < _namespaces.length
? _namespaces[_selectedDrawerIndex]
: null;
@override
void afterFirstLayout(BuildContext context) {
_loadNamespaces();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
List<Widget> namespacesList = <Widget>[];
_namespaces
.asMap()
.forEach((i, namespace) => namespacesList.add(new ListTile(
leading: const Icon(Icons.folder),
title: new Text(namespace.title),
selected: i == _selectedDrawerIndex,
onTap: () => _onSelectItem(i),
)));
if(_selectedDrawerIndex > -1) {
return new WillPopScope(
child: NamespacePage(namespace: _namespaces[_selectedDrawerIndex]),
onWillPop: () async {setState(() {
_selectedDrawerIndex = -2;
});
return false;});
}
return this._loading
? Center(child: CircularProgressIndicator())
: Scaffold(
body: RefreshIndicator(
child: ListView(
padding: EdgeInsets.zero,
children: ListTile.divideTiles(
context: context, tiles: namespacesList)
.toList()),
onRefresh: _loadNamespaces,
),
floatingActionButton: Builder(
builder: (context) => FloatingActionButton(
onPressed: () => _addNamespaceDialog(context),
child: const Icon(Icons.add))));
}
Future<void> _loadNamespaces() {
return VikunjaGlobal.of(context).namespaceService.getAll().then((result) {
setState(() {
_loading = false;
if (result != null) _namespaces = result;
});
});
}
_onSelectItem(int index) {
setState(() => _selectedDrawerIndex = index);
}
_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) {
final currentUser = VikunjaGlobal.of(context).currentUser;
if (currentUser == null) {
return;
}
VikunjaGlobal.of(context)
.namespaceService
.create(Namespace(title: name, owner: currentUser))
.then((_) {
_loadNamespaces();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('The namespace was created successfully!'),
));
}).catchError((error) => showDialog(
context: context, builder: (context) => ErrorDialog(error: error)));
}
}

View File

@ -55,9 +55,6 @@ class SettingsPageState extends State<SettingsPage> {
Widget build(BuildContext context) {
if (!initialized) init();
return new Scaffold(
appBar: AppBar(
title: Text("Settings"),
),
body: Column(
children: [
taskListList != null