lemmur-app-android/lib/pages/profile_tab.dart

101 lines
3.0 KiB
Dart
Raw Normal View History

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';
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
final actions = [
IconButton(
2021-01-03 19:43:39 +01:00
icon: const Icon(Icons.settings),
onPressed: () {
2021-01-03 19:43:39 +01:00
goTo(context, (_) => const SettingsPage());
},
)
];
if (accountsStore.hasNoAccount) {
return Scaffold(
2021-02-09 15:12:13 +01:00
appBar: AppBar(actions: actions),
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: () {
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
)
],
),
),
);
}
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]);
},
2021-02-09 15:12:13 +01:00
buttonBuilder: (context, displayValue, onPressed) => TextButton(
onPressed: onPressed,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
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
),
),
actions: actions,
),
body: UserProfile(
2021-04-11 18:27:22 +02:00
userId: accountsStore.defaultUserData!.userId,
instanceHost: accountsStore.defaultInstanceHost!,
),
2020-08-31 01:04:08 +02:00
);
}
}