diff --git a/lib/pages/profile_tab.dart b/lib/pages/profile_tab.dart index 5dfba77..a7bd4ba 100644 --- a/lib/pages/profile_tab.dart +++ b/lib/pages/profile_tab.dart @@ -4,6 +4,7 @@ import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:provider/provider.dart'; import '../stores/accounts_store.dart'; +import '../widgets/bottom_modal.dart'; import '../widgets/user_profile.dart'; import 'settings.dart'; @@ -39,7 +40,51 @@ class UserProfileTab extends HookWidget { ), ], ), - onPressed: () {}, // TODO: should open bottomsheet + onPressed: () { + showModalBottomSheet( + context: context, + backgroundColor: Colors.transparent, + builder: (_) { + var userTags = []; + + ctx + .read() + .users + .forEach((instanceUrl, value) { + value.forEach((username, _) { + userTags.add('$username@$instanceUrl'); + }); + }); + + return Observer( + builder: (ctx) { + var user = ctx.watch().defaultUser; + var instanceUrl = user.actorId.split('/')[2]; + + return BottomModal( + title: 'account', + child: Column( + children: [ + for (final tag in userTags) + RadioListTile( + value: tag, + title: Text(tag), + groupValue: '${user.name}@$instanceUrl', + onChanged: (selected) { + var userTag = selected.split('@'); + ctx.read().setDefaultAccount( + userTag[1], userTag[0]); + Navigator.of(ctx).pop(); + }, + ) + ], + ), + ); + }, + ); + }, + ); + }, ), actions: [ IconButton( diff --git a/lib/widgets/bottom_modal.dart b/lib/widgets/bottom_modal.dart new file mode 100644 index 0000000..4d7e058 --- /dev/null +++ b/lib/widgets/bottom_modal.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; + +class BottomModal extends StatelessWidget { + final Widget child; + final String title; + + BottomModal({@required this.child, this.title}); + + @override + Widget build(BuildContext context) { + var theme = Theme.of(context); + + return Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + padding: const EdgeInsets.only(top: 10), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(const Radius.circular(10.0)), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (title != null) ...[ + Padding( + padding: const EdgeInsets.only(left: 70), + child: Text( + 'account', + style: theme.textTheme.subtitle2, + textAlign: TextAlign.left, + ), + ), + Divider() + ], + child, + ], + ), + ), + ); + } +} diff --git a/lib/widgets/user_profile.dart b/lib/widgets/user_profile.dart index 1662dd3..9ce8e6d 100644 --- a/lib/widgets/user_profile.dart +++ b/lib/widgets/user_profile.dart @@ -23,7 +23,7 @@ class UserProfile extends HookWidget { Widget build(BuildContext context) { var theme = Theme.of(context); - var userViewSnap = useFuture(_userView); + var userViewSnap = useFuture(_userView, preserveState: false); Widget bio;