From 99c49e3df2dbff5cb3f5e9473cf52adbdc787057 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Thu, 20 Feb 2025 17:19:04 +0100 Subject: [PATCH] fix: Crash in settings when using MAS --- lib/pages/settings/settings.dart | 8 - lib/pages/settings/settings_view.dart | 383 +++++++++--------- .../settings_homeserver_view.dart | 2 +- 3 files changed, 190 insertions(+), 203 deletions(-) diff --git a/lib/pages/settings/settings.dart b/lib/pages/settings/settings.dart index 6e822f4b7..484250940 100644 --- a/lib/pages/settings/settings.dart +++ b/lib/pages/settings/settings.dart @@ -199,14 +199,6 @@ class SettingsController extends State { checkBootstrap(); } - Future getOidcAccountManageUrl() async { - final client = Matrix.of(context).client; - final wellKnown = client.wellKnown ?? await client.getWellknown(); - return wellKnown.additionalProperties - .tryGetMap('org.matrix.msc2965.authentication') - ?.tryGet('account'); - } - @override Widget build(BuildContext context) { final client = Matrix.of(context).client; diff --git a/lib/pages/settings/settings_view.dart b/lib/pages/settings/settings_view.dart index eace397bc..baa719550 100644 --- a/lib/pages/settings/settings_view.dart +++ b/lib/pages/settings/settings_view.dart @@ -25,6 +25,12 @@ class SettingsView extends StatelessWidget { final showChatBackupBanner = controller.showChatBackupBanner; final activeRoute = GoRouter.of(context).routeInformationProvider.value.uri.path; + final accountManageUrl = Matrix.of(context) + .client + .wellKnown + ?.additionalProperties + .tryGetMap('org.matrix.msc2965.authentication') + ?.tryGet('account'); return Row( children: [ if (FluffyThemes.isColumnMode(context)) ...[ @@ -52,208 +58,197 @@ class SettingsView extends StatelessWidget { ), body: ListTileTheme( iconColor: theme.colorScheme.onSurface, - child: FutureBuilder( - future: controller.getOidcAccountManageUrl(), - builder: (context, snapshot) { - final accountManageUrl = snapshot.data; - return ListView( - key: const Key('SettingsListViewContent'), - children: [ - FutureBuilder( - future: controller.profileFuture, - builder: (context, snapshot) { - final profile = snapshot.data; - final mxid = Matrix.of(context).client.userID ?? - L10n.of(context).user; - final displayname = - profile?.displayName ?? mxid.localpart ?? mxid; - return Row( - children: [ - Padding( - padding: const EdgeInsets.all(32.0), - child: Stack( - children: [ - Avatar( - mxContent: profile?.avatarUrl, - name: displayname, - size: Avatar.defaultSize * 2.5, - ), - if (profile != null) - Positioned( - bottom: 0, - right: 0, - child: FloatingActionButton.small( - elevation: 2, - onPressed: controller.setAvatarAction, - heroTag: null, - child: const Icon( - Icons.camera_alt_outlined, - ), - ), - ), - ], + child: ListView( + key: const Key('SettingsListViewContent'), + children: [ + FutureBuilder( + future: controller.profileFuture, + builder: (context, snapshot) { + final profile = snapshot.data; + final mxid = Matrix.of(context).client.userID ?? + L10n.of(context).user; + final displayname = + profile?.displayName ?? mxid.localpart ?? mxid; + return Row( + children: [ + Padding( + padding: const EdgeInsets.all(32.0), + child: Stack( + children: [ + Avatar( + mxContent: profile?.avatarUrl, + name: displayname, + size: Avatar.defaultSize * 2.5, ), - ), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - TextButton.icon( - onPressed: - controller.setDisplaynameAction, - icon: const Icon( - Icons.edit_outlined, - size: 16, - ), - style: TextButton.styleFrom( - foregroundColor: - theme.colorScheme.onSurface, - iconColor: theme.colorScheme.onSurface, - ), - label: Text( - displayname, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: const TextStyle( - fontSize: 18, - ), + if (profile != null) + Positioned( + bottom: 0, + right: 0, + child: FloatingActionButton.small( + elevation: 2, + onPressed: controller.setAvatarAction, + heroTag: null, + child: const Icon( + Icons.camera_alt_outlined, ), ), - TextButton.icon( - onPressed: () => - FluffyShare.share(mxid, context), - icon: const Icon( - Icons.copy_outlined, - size: 14, - ), - style: TextButton.styleFrom( - foregroundColor: - theme.colorScheme.secondary, - iconColor: theme.colorScheme.secondary, - ), - label: Text( - mxid, - maxLines: 1, - overflow: TextOverflow.ellipsis, - // style: const TextStyle(fontSize: 12), - ), - ), - ], - ), - ), - ], - ); - }, - ), - if (accountManageUrl != null) - ListTile( - leading: const Icon(Icons.account_circle_outlined), - title: Text(L10n.of(context).manageAccount), - trailing: const Icon(Icons.open_in_new_outlined), - onTap: () => launchUrlString( - accountManageUrl, - mode: LaunchMode.inAppBrowserView, + ), + ], + ), ), - ), - Divider(color: theme.dividerColor), - if (showChatBackupBanner == null) - ListTile( - leading: const Icon(Icons.backup_outlined), - title: Text(L10n.of(context).chatBackup), - trailing: const CircularProgressIndicator.adaptive(), - ) - else - SwitchListTile.adaptive( - controlAffinity: ListTileControlAffinity.trailing, - value: controller.showChatBackupBanner == false, - secondary: const Icon(Icons.backup_outlined), - title: Text(L10n.of(context).chatBackup), - onChanged: controller.firstRunBootstrapAction, - ), - Divider( - color: theme.dividerColor, + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextButton.icon( + onPressed: controller.setDisplaynameAction, + icon: const Icon( + Icons.edit_outlined, + size: 16, + ), + style: TextButton.styleFrom( + foregroundColor: + theme.colorScheme.onSurface, + iconColor: theme.colorScheme.onSurface, + ), + label: Text( + displayname, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: const TextStyle( + fontSize: 18, + ), + ), + ), + TextButton.icon( + onPressed: () => + FluffyShare.share(mxid, context), + icon: const Icon( + Icons.copy_outlined, + size: 14, + ), + style: TextButton.styleFrom( + foregroundColor: + theme.colorScheme.secondary, + iconColor: theme.colorScheme.secondary, + ), + label: Text( + mxid, + maxLines: 1, + overflow: TextOverflow.ellipsis, + // style: const TextStyle(fontSize: 12), + ), + ), + ], + ), + ), + ], + ); + }, + ), + if (accountManageUrl != null) + ListTile( + leading: const Icon(Icons.account_circle_outlined), + title: Text(L10n.of(context).manageAccount), + trailing: const Icon(Icons.open_in_new_outlined), + onTap: () => launchUrlString( + accountManageUrl, + mode: LaunchMode.inAppBrowserView, ), - ListTile( - leading: const Icon(Icons.format_paint_outlined), - title: Text(L10n.of(context).changeTheme), - tileColor: - activeRoute.startsWith('/rooms/settings/style') - ? theme.colorScheme.surfaceContainerHigh - : null, - onTap: () => context.go('/rooms/settings/style'), - ), - ListTile( - leading: const Icon(Icons.notifications_outlined), - title: Text(L10n.of(context).notifications), - tileColor: activeRoute - .startsWith('/rooms/settings/notifications') + ), + Divider(color: theme.dividerColor), + if (showChatBackupBanner == null) + ListTile( + leading: const Icon(Icons.backup_outlined), + title: Text(L10n.of(context).chatBackup), + trailing: const CircularProgressIndicator.adaptive(), + ) + else + SwitchListTile.adaptive( + controlAffinity: ListTileControlAffinity.trailing, + value: controller.showChatBackupBanner == false, + secondary: const Icon(Icons.backup_outlined), + title: Text(L10n.of(context).chatBackup), + onChanged: controller.firstRunBootstrapAction, + ), + Divider( + color: theme.dividerColor, + ), + ListTile( + leading: const Icon(Icons.format_paint_outlined), + title: Text(L10n.of(context).changeTheme), + tileColor: activeRoute.startsWith('/rooms/settings/style') + ? theme.colorScheme.surfaceContainerHigh + : null, + onTap: () => context.go('/rooms/settings/style'), + ), + ListTile( + leading: const Icon(Icons.notifications_outlined), + title: Text(L10n.of(context).notifications), + tileColor: + activeRoute.startsWith('/rooms/settings/notifications') ? theme.colorScheme.surfaceContainerHigh : null, - onTap: () => - context.go('/rooms/settings/notifications'), + onTap: () => context.go('/rooms/settings/notifications'), + ), + ListTile( + leading: const Icon(Icons.devices_outlined), + title: Text(L10n.of(context).devices), + onTap: () => context.go('/rooms/settings/devices'), + tileColor: activeRoute.startsWith('/rooms/settings/devices') + ? theme.colorScheme.surfaceContainerHigh + : null, + ), + ListTile( + leading: const Icon(Icons.forum_outlined), + title: Text(L10n.of(context).chat), + onTap: () => context.go('/rooms/settings/chat'), + tileColor: activeRoute.startsWith('/rooms/settings/chat') + ? theme.colorScheme.surfaceContainerHigh + : null, + ), + ListTile( + leading: const Icon(Icons.shield_outlined), + title: Text(L10n.of(context).security), + onTap: () => context.go('/rooms/settings/security'), + tileColor: + activeRoute.startsWith('/rooms/settings/security') + ? theme.colorScheme.surfaceContainerHigh + : null, + ), + Divider(color: theme.dividerColor), + ListTile( + leading: const Icon(Icons.dns_outlined), + title: Text( + L10n.of(context).aboutHomeserver( + Matrix.of(context).client.userID?.domain ?? + 'homeserver', ), - ListTile( - leading: const Icon(Icons.devices_outlined), - title: Text(L10n.of(context).devices), - onTap: () => context.go('/rooms/settings/devices'), - tileColor: - activeRoute.startsWith('/rooms/settings/devices') - ? theme.colorScheme.surfaceContainerHigh - : null, - ), - ListTile( - leading: const Icon(Icons.forum_outlined), - title: Text(L10n.of(context).chat), - onTap: () => context.go('/rooms/settings/chat'), - tileColor: - activeRoute.startsWith('/rooms/settings/chat') - ? theme.colorScheme.surfaceContainerHigh - : null, - ), - ListTile( - leading: const Icon(Icons.shield_outlined), - title: Text(L10n.of(context).security), - onTap: () => context.go('/rooms/settings/security'), - tileColor: - activeRoute.startsWith('/rooms/settings/security') - ? theme.colorScheme.surfaceContainerHigh - : null, - ), - Divider(color: theme.dividerColor), - ListTile( - leading: const Icon(Icons.dns_outlined), - title: Text( - L10n.of(context).aboutHomeserver( - Matrix.of(context).client.userID?.domain ?? - 'homeserver', - ), - ), - onTap: () => context.go('/rooms/settings/homeserver'), - tileColor: - activeRoute.startsWith('/rooms/settings/homeserver') - ? theme.colorScheme.surfaceContainerHigh - : null, - ), - ListTile( - leading: const Icon(Icons.privacy_tip_outlined), - title: Text(L10n.of(context).privacy), - onTap: () => launchUrlString(AppConfig.privacyUrl), - ), - ListTile( - leading: const Icon(Icons.info_outline_rounded), - title: Text(L10n.of(context).about), - onTap: () => PlatformInfos.showDialog(context), - ), - Divider(color: theme.dividerColor), - ListTile( - leading: const Icon(Icons.logout_outlined), - title: Text(L10n.of(context).logout), - onTap: controller.logoutAction, - ), - ], - ); - }, + ), + onTap: () => context.go('/rooms/settings/homeserver'), + tileColor: + activeRoute.startsWith('/rooms/settings/homeserver') + ? theme.colorScheme.surfaceContainerHigh + : null, + ), + ListTile( + leading: const Icon(Icons.privacy_tip_outlined), + title: Text(L10n.of(context).privacy), + onTap: () => launchUrlString(AppConfig.privacyUrl), + ), + ListTile( + leading: const Icon(Icons.info_outline_rounded), + title: Text(L10n.of(context).about), + onTap: () => PlatformInfos.showDialog(context), + ), + Divider(color: theme.dividerColor), + ListTile( + leading: const Icon(Icons.logout_outlined), + title: Text(L10n.of(context).logout), + onTap: controller.logoutAction, + ), + ], ), ), ), diff --git a/lib/pages/settings_homeserver/settings_homeserver_view.dart b/lib/pages/settings_homeserver/settings_homeserver_view.dart index 712bcd707..6de7102e8 100644 --- a/lib/pages/settings_homeserver/settings_homeserver_view.dart +++ b/lib/pages/settings_homeserver/settings_homeserver_view.dart @@ -35,7 +35,7 @@ class SettingsHomeserverView extends StatelessWidget { ), ), body: MaxWidthBody( - withScrolling: false, + withScrolling: true, child: SelectionArea( child: Column( mainAxisSize: MainAxisSize.min,