:C
This commit is contained in:
parent
9848c462f8
commit
1e3518554b
|
@ -33,12 +33,17 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
||||||
bool _loading = true;
|
bool _loading = true;
|
||||||
|
|
||||||
User get currentUser => _currentUser;
|
User get currentUser => _currentUser;
|
||||||
|
|
||||||
Client get client => _client;
|
Client get client => _client;
|
||||||
|
|
||||||
UserManager get userManager => new UserManager(_storage);
|
UserManager get userManager => new UserManager(_storage);
|
||||||
|
|
||||||
UserService newUserService(base) => new UserAPIService(Client(null, base));
|
UserService newUserService(base) => new UserAPIService(Client(null, base));
|
||||||
|
|
||||||
NamespaceService get namespaceService => new NamespaceAPIService(client);
|
NamespaceService get namespaceService => new NamespaceAPIService(client);
|
||||||
|
|
||||||
TaskService get taskService => new TaskAPIService(client);
|
TaskService get taskService => new TaskAPIService(client);
|
||||||
|
|
||||||
ListService get listService => new ListAPIService(client);
|
ListService get listService => new ListAPIService(client);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -72,6 +77,20 @@ class VikunjaGlobalState extends State<VikunjaGlobal> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void logoutUser(BuildContext context) {
|
||||||
|
_storage.deleteAll().then((_) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
setState(() {
|
||||||
|
_client = null;
|
||||||
|
_currentUser = null;
|
||||||
|
});
|
||||||
|
}).catchError((err) {
|
||||||
|
Scaffold.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text('An error occured while logging out!'),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _loadCurrentUser() async {
|
void _loadCurrentUser() async {
|
||||||
var currentUser = await _storage.read(key: 'currentUser');
|
var currentUser = await _storage.read(key: 'currentUser');
|
||||||
if (currentUser == null) {
|
if (currentUser == null) {
|
||||||
|
|
|
@ -17,31 +17,59 @@ class HomePage extends StatefulWidget {
|
||||||
|
|
||||||
class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
|
class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
|
||||||
List<Namespace> _namespaces = [];
|
List<Namespace> _namespaces = [];
|
||||||
|
|
||||||
Namespace get _currentNamespace =>
|
Namespace get _currentNamespace =>
|
||||||
_selectedDrawerIndex >= 0 && _selectedDrawerIndex < _namespaces.length
|
_selectedDrawerIndex >= 0 && _selectedDrawerIndex < _namespaces.length
|
||||||
? _namespaces[_selectedDrawerIndex]
|
? _namespaces[_selectedDrawerIndex]
|
||||||
: null;
|
: null;
|
||||||
int _selectedDrawerIndex = -1;
|
int _selectedDrawerIndex = -1;
|
||||||
bool _loading = true;
|
bool _loading = true;
|
||||||
|
bool _showUserDetails = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void afterFirstLayout(BuildContext context) {
|
void afterFirstLayout(BuildContext context) {
|
||||||
_loadNamespaces();
|
_loadNamespaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Widget _namespacesWidget() {
|
||||||
Widget build(BuildContext context) {
|
List<Widget> namespacesList = <Widget>[];
|
||||||
var currentUser = VikunjaGlobal.of(context).currentUser;
|
|
||||||
List<Widget> drawerOptions = <Widget>[];
|
|
||||||
_namespaces
|
_namespaces
|
||||||
.asMap()
|
.asMap()
|
||||||
.forEach((i, namespace) => drawerOptions.add(new ListTile(
|
.forEach((i, namespace) => namespacesList.add(new ListTile(
|
||||||
leading: const Icon(Icons.folder),
|
leading: const Icon(Icons.folder),
|
||||||
title: new Text(namespace.name),
|
title: new Text(namespace.name),
|
||||||
selected: i == _selectedDrawerIndex,
|
selected: i == _selectedDrawerIndex,
|
||||||
onTap: () => _onSelectItem(i),
|
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>[
|
||||||
|
ListTile(
|
||||||
|
title: Text('Logout'),
|
||||||
|
leading: Icon(Icons.exit_to_app),
|
||||||
|
onTap: () {
|
||||||
|
VikunjaGlobal.of(context).logoutUser(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var currentUser = VikunjaGlobal.of(context).currentUser;
|
||||||
|
|
||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
appBar: AppBar(title: new Text(_currentNamespace?.name ?? 'Vikunja')),
|
appBar: AppBar(title: new Text(_currentNamespace?.name ?? 'Vikunja')),
|
||||||
drawer: new Drawer(
|
drawer: new Drawer(
|
||||||
|
@ -49,6 +77,11 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
|
||||||
new UserAccountsDrawerHeader(
|
new UserAccountsDrawerHeader(
|
||||||
accountEmail: currentUser == null ? null : Text(currentUser.email),
|
accountEmail: currentUser == null ? null : Text(currentUser.email),
|
||||||
accountName: currentUser == null ? null : Text(currentUser.username),
|
accountName: currentUser == null ? null : Text(currentUser.username),
|
||||||
|
onDetailsPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_showUserDetails = !_showUserDetails;
|
||||||
|
});
|
||||||
|
},
|
||||||
currentAccountPicture: currentUser == null
|
currentAccountPicture: currentUser == null
|
||||||
? null
|
? null
|
||||||
: CircleAvatar(
|
: CircleAvatar(
|
||||||
|
@ -61,17 +94,11 @@ class HomePageState extends State<HomePage> with AfterLayoutMixin<HomePage> {
|
||||||
Theme.of(context).primaryColor, BlendMode.multiply)),
|
Theme.of(context).primaryColor, BlendMode.multiply)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
new Expanded(
|
new Builder(
|
||||||
child: this._loading
|
builder: (BuildContext context) => Expanded(
|
||||||
? Center(child: CircularProgressIndicator())
|
child: _showUserDetails
|
||||||
: RefreshIndicator(
|
? _userDetailsWidget(context)
|
||||||
child: ListView(
|
: _namespacesWidget())),
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
children: ListTile.divideTiles(
|
|
||||||
context: context, tiles: drawerOptions)
|
|
||||||
.toList()),
|
|
||||||
onRefresh: _loadNamespaces,
|
|
||||||
)),
|
|
||||||
new Align(
|
new Align(
|
||||||
alignment: FractionalOffset.bottomCenter,
|
alignment: FractionalOffset.bottomCenter,
|
||||||
child: Builder(
|
child: Builder(
|
||||||
|
|
Reference in New Issue