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';
|
2021-02-09 15:12:13 +01:00
|
|
|
import '../widgets/radio_picker.dart';
|
2020-08-31 12:05:45 +02:00
|
|
|
import '../widgets/user_profile.dart';
|
2021-02-09 20:39:45 +01:00
|
|
|
import 'saved_page.dart';
|
2021-09-14 23:45:26 +02:00
|
|
|
import 'settings/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 {
|
2021-01-03 18:21:56 +01:00
|
|
|
const 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(
|
2021-01-03 19:43:39 +01:00
|
|
|
icon: const Icon(Icons.settings),
|
2020-12-03 22:45:50 +01:00
|
|
|
onPressed: () {
|
2021-01-03 19:43:39 +01:00
|
|
|
goTo(context, (_) => const SettingsPage());
|
2020-12-03 22:45:50 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
];
|
|
|
|
|
2020-10-26 00:43:37 +01:00
|
|
|
if (accountsStore.hasNoAccount) {
|
|
|
|
return Scaffold(
|
2021-02-09 15:12:13 +01:00
|
|
|
appBar: AppBar(actions: actions),
|
2020-10-26 00:43:37 +01:00
|
|
|
body: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2021-01-03 19:43:39 +01:00
|
|
|
const Text('No account was added.'),
|
2021-02-09 15:12:13 +01:00
|
|
|
TextButton.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
|
|
|
},
|
2021-01-03 19:43:39 +01:00
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
label: const 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,
|
|
|
|
appBar: AppBar(
|
2021-02-09 19:25:17 +01:00
|
|
|
leading: IconButton(
|
|
|
|
onPressed: () => goTo(context, (context) => SavedPage()),
|
|
|
|
icon: const Icon(Icons.bookmark),
|
|
|
|
),
|
2021-02-09 15:12:13 +01:00
|
|
|
title: RadioPicker<String>(
|
|
|
|
title: 'account',
|
|
|
|
values: accountsStore.loggedInInstances
|
|
|
|
.expand(
|
|
|
|
(instanceHost) => accountsStore
|
|
|
|
.usernamesFor(instanceHost)
|
|
|
|
.map((username) => '$username@$instanceHost'),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
groupValue:
|
|
|
|
'${accountsStore.defaultUsername}@${accountsStore.defaultInstanceHost}',
|
|
|
|
onChanged: (value) {
|
|
|
|
final userTag = value.split('@');
|
|
|
|
accountsStore.setDefaultAccount(userTag[1], userTag[0]);
|
2020-10-26 00:43:37 +01:00
|
|
|
},
|
2021-02-09 15:12:13 +01:00
|
|
|
buttonBuilder: (context, displayValue, onPressed) => TextButton(
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2021-11-03 22:50:03 +01:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
displayValue,
|
|
|
|
style: theme.appBarTheme.titleTextStyle,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
softWrap: false,
|
|
|
|
),
|
2021-02-09 15:12:13 +01:00
|
|
|
),
|
|
|
|
const Icon(Icons.expand_more),
|
|
|
|
],
|
|
|
|
),
|
2021-01-03 18:13:25 +01:00
|
|
|
),
|
2020-10-26 00:43:37 +01:00
|
|
|
),
|
2020-12-03 22:45:50 +01:00
|
|
|
actions: actions,
|
2020-10-26 00:43:37 +01:00
|
|
|
),
|
|
|
|
body: UserProfile(
|
2021-04-11 18:27:22 +02:00
|
|
|
userId: accountsStore.defaultUserData!.userId,
|
2021-04-09 00:11:44 +02:00
|
|
|
instanceHost: accountsStore.defaultInstanceHost!,
|
2020-10-26 00:43:37 +01:00
|
|
|
),
|
2020-08-31 01:04:08 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|