2020-09-16 22:53:04 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-08-31 01:04:08 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2020-08-31 12:05:45 +02:00
|
|
|
|
2020-09-17 00:24:49 +02:00
|
|
|
import '../hooks/stores.dart';
|
2020-09-16 22:53:04 +02:00
|
|
|
import '../util/goto.dart';
|
2020-09-01 21:36:58 +02:00
|
|
|
import '../widgets/bottom_modal.dart';
|
2020-08-31 12:05:45 +02:00
|
|
|
import '../widgets/user_profile.dart';
|
2020-08-31 16:17:39 +02:00
|
|
|
import 'settings.dart';
|
2020-08-31 01:04:08 +02:00
|
|
|
|
2020-09-30 19:05:00 +02:00
|
|
|
/// Profile page for a logged in user. The difference between this and
|
2020-09-30 19:37:56 +02:00
|
|
|
/// UserPage is that here you have access to settings
|
2020-08-31 01:04:08 +02:00
|
|
|
class UserProfileTab extends HookWidget {
|
2020-09-01 13:22:37 +02:00
|
|
|
UserProfileTab();
|
2020-08-31 01:04:08 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final theme = Theme.of(context);
|
2020-09-16 23:15:42 +02:00
|
|
|
final accountsStore = useAccountsStore();
|
2020-08-31 01:04:08 +02:00
|
|
|
|
2020-12-03 22:45:50 +01:00
|
|
|
final actions = [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.settings),
|
|
|
|
onPressed: () {
|
|
|
|
goTo(context, (_) => SettingsPage());
|
|
|
|
},
|
|
|
|
)
|
|
|
|
];
|
|
|
|
|
2020-10-26 00:43:37 +01:00
|
|
|
if (accountsStore.hasNoAccount) {
|
|
|
|
return Scaffold(
|
2020-12-03 22:45:50 +01:00
|
|
|
appBar: AppBar(
|
|
|
|
actions: actions,
|
|
|
|
backgroundColor: Colors.transparent,
|
2020-12-03 22:53:29 +01:00
|
|
|
iconTheme: theme.iconTheme,
|
2020-12-03 22:45:50 +01:00
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
),
|
2020-10-26 00:43:37 +01:00
|
|
|
body: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text('No account was added.'),
|
|
|
|
FlatButton.icon(
|
2020-09-01 13:22:37 +02:00
|
|
|
onPressed: () {
|
2020-10-26 00:43:37 +01:00
|
|
|
goTo(context, (_) => AccountsConfigPage());
|
2020-09-01 13:22:37 +02:00
|
|
|
},
|
2020-10-26 00:43:37 +01:00
|
|
|
icon: Icon(Icons.add),
|
|
|
|
label: Text('Add account'),
|
2020-09-01 13:22:37 +02:00
|
|
|
)
|
2020-08-31 03:54:24 +02:00
|
|
|
],
|
|
|
|
),
|
2020-10-26 00:43:37 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
// TODO: this is not visible in light mode when the sliver app bar
|
|
|
|
// in UserProfile is folded
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
centerTitle: true,
|
|
|
|
title: FlatButton(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
// TODO: fix overflow issues
|
|
|
|
'@${accountsStore.defaultUsername}',
|
|
|
|
style: theme.primaryTextTheme.headline6,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
),
|
|
|
|
Icon(
|
|
|
|
Icons.expand_more,
|
|
|
|
color: theme.primaryIconTheme.color,
|
|
|
|
),
|
|
|
|
],
|
2020-09-01 13:22:37 +02:00
|
|
|
),
|
2020-10-26 00:43:37 +01:00
|
|
|
onPressed: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: (ctx) {
|
|
|
|
final userTags = <String>[];
|
|
|
|
|
|
|
|
accountsStore.tokens.forEach((instanceUrl, value) {
|
|
|
|
value.forEach((username, _) {
|
|
|
|
userTags.add('$username@$instanceUrl');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return BottomModal(
|
|
|
|
title: 'account',
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
for (final tag in userTags)
|
|
|
|
RadioListTile<String>(
|
|
|
|
value: tag,
|
|
|
|
title: Text(tag),
|
|
|
|
groupValue: '${accountsStore.defaultUsername}'
|
|
|
|
'@${accountsStore.defaultInstanceUrl}',
|
|
|
|
onChanged: (selected) {
|
|
|
|
final userTag = selected.split('@');
|
|
|
|
accountsStore.setDefaultAccount(
|
|
|
|
userTag[1], userTag[0]);
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2020-12-03 22:45:50 +01:00
|
|
|
actions: actions,
|
2020-10-26 00:43:37 +01:00
|
|
|
),
|
|
|
|
body: UserProfile(
|
|
|
|
userId: accountsStore.defaultToken.payload.id,
|
|
|
|
instanceUrl: accountsStore.defaultInstanceUrl,
|
|
|
|
),
|
2020-08-31 01:04:08 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|