2020-08-31 01:04:08 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2020-09-01 13:22:37 +02:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2020-08-31 12:05:45 +02:00
|
|
|
|
2020-09-01 13:22:37 +02:00
|
|
|
import '../stores/accounts_store.dart';
|
2020-09-09 17:41:54 +02:00
|
|
|
import '../util/api_extensions.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
|
|
|
|
|
|
|
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) {
|
|
|
|
var theme = Theme.of(context);
|
|
|
|
|
2020-09-01 13:22:37 +02:00
|
|
|
return Observer(
|
|
|
|
builder: (ctx) {
|
2020-09-08 21:45:17 +02:00
|
|
|
if (ctx.watch<AccountsStore>().hasNoAccount) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text('No account was added.'),
|
|
|
|
FlatButton.icon(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (_) => AccountsConfigPage()));
|
|
|
|
},
|
|
|
|
icon: Icon(Icons.add),
|
|
|
|
label: Text('Add account'),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-01 13:22:37 +02:00
|
|
|
var user = ctx.watch<AccountsStore>().defaultUser;
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
extendBodyBehindAppBar: true,
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
centerTitle: true,
|
|
|
|
title: FlatButton(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
2020-09-03 22:08:32 +02:00
|
|
|
'@${user.name}', // TODO: fix overflow issues
|
|
|
|
style: theme.primaryTextTheme.headline6,
|
|
|
|
overflow: TextOverflow.fade,
|
2020-09-01 13:22:37 +02:00
|
|
|
),
|
|
|
|
Icon(
|
|
|
|
Icons.expand_more,
|
|
|
|
color: theme.primaryIconTheme.color,
|
|
|
|
),
|
|
|
|
],
|
2020-08-31 03:54:24 +02:00
|
|
|
),
|
2020-09-01 21:36:58 +02:00
|
|
|
onPressed: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: (_) {
|
|
|
|
var userTags = <String>[];
|
|
|
|
|
|
|
|
ctx
|
|
|
|
.read<AccountsStore>()
|
|
|
|
.users
|
|
|
|
.forEach((instanceUrl, value) {
|
|
|
|
value.forEach((username, _) {
|
|
|
|
userTags.add('$username@$instanceUrl');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return Observer(
|
|
|
|
builder: (ctx) {
|
|
|
|
var user = ctx.watch<AccountsStore>().defaultUser;
|
2020-09-09 17:41:54 +02:00
|
|
|
var instanceUrl = user.instanceUrl;
|
2020-09-01 21:36:58 +02:00
|
|
|
|
|
|
|
return BottomModal(
|
|
|
|
title: 'account',
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
for (final tag in userTags)
|
|
|
|
RadioListTile<String>(
|
|
|
|
value: tag,
|
|
|
|
title: Text(tag),
|
|
|
|
groupValue: '${user.name}@$instanceUrl',
|
|
|
|
onChanged: (selected) {
|
|
|
|
var userTag = selected.split('@');
|
|
|
|
ctx.read<AccountsStore>().setDefaultAccount(
|
|
|
|
userTag[1], userTag[0]);
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
2020-09-01 13:22:37 +02:00
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
2020-09-03 23:18:48 +02:00
|
|
|
icon: Icon(Icons.settings),
|
2020-09-01 13:22:37 +02:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context)
|
2020-09-03 14:41:30 +02:00
|
|
|
.push(MaterialPageRoute(builder: (_) => SettingsPage()));
|
2020-09-01 13:22:37 +02:00
|
|
|
},
|
|
|
|
)
|
2020-08-31 03:54:24 +02:00
|
|
|
],
|
|
|
|
),
|
2020-09-01 13:22:37 +02:00
|
|
|
body: UserProfile(
|
|
|
|
userId: user.id,
|
2020-09-09 17:41:54 +02:00
|
|
|
instanceUrl: user.instanceUrl,
|
2020-09-01 13:22:37 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2020-08-31 01:04:08 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|