diff --git a/lib/controllers/settings_sections.dart b/lib/controllers/settings_sections.dart index 042b42b..149fe30 100644 --- a/lib/controllers/settings_sections.dart +++ b/lib/controllers/settings_sections.dart @@ -1,5 +1,4 @@ import "dart:io"; - import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:material_ui/material_ui.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; @@ -9,7 +8,6 @@ import "package:nexus/controllers/account_data.dart"; import "package:nexus/controllers/client.dart"; import "package:nexus/controllers/client_state.dart"; import "package:nexus/controllers/settings.dart"; -import "package:nexus/controllers/spec_versions.dart"; import "package:nexus/models/account_data.dart"; import "package:nexus/models/settings_category.dart"; import "package:nexus/main.dart"; @@ -20,6 +18,9 @@ class SettingsSectionsController @override Future>> build() async { final settings = await ref.watch(SettingsController.provider.future); + final specVersionsResponse = await ref + .watch(ClientController.provider.notifier) + .getSpecVersions(); return .new({ "General": .new([ @@ -48,7 +49,8 @@ class SettingsSectionsController .new( title: "Use Dynamic Theme", icon: Icons.palette, - description: "Toggle on or off Dynamic Theme. Only available on Android, Linux, Windows, or MacOS.", + description: + "Toggle on or off Dynamic Theme. Only available on Android, Linux, Windows, or MacOS.", builder: (title, description, icon) => SwitchListTile( title: Text(title), subtitle: Text(description), @@ -74,7 +76,8 @@ class SettingsSectionsController settings: .new([ .new( title: "Linux Mobile Mode", - description: "Enables some fixes for Linux mobile, e.g. disabling dragging appbar for moving window.", + description: + "Enables some fixes for Linux mobile, e.g. disabling dragging appbar for moving window.", icon: Icons.construction, builder: (title, description, icon) => SwitchListTile( title: Text(title), @@ -101,51 +104,40 @@ class SettingsSectionsController settings: .new([ .new( title: "Invite Blocking", - description: "Block invites, either completely, or block only invites from users without shared private rooms (depends on server support).", + description: + "Block invites, either completely, or block only invites from users without shared private rooms (depends on server support).", builder: (title, description, icon) => Consumer( - builder: (context, ref, _) { - final specVersionsResponse = ref.watch( - SpecVersionsController.provider, - ); - return DialogListTile( - icon: Icon(icon), - title: title, - subtitle: Text(description), - initialValue: ref - .watch(AccountDataController.provider) - .invitePermissionConfig - .defaultAction, - options: - specVersionsResponse.maybeWhen( - data: (data) => data.unstableFeatures.msc4494, - orElse: () => true, - ) - ? DefaultInviteAction.values - : IList(DefaultInviteAction.values) - .remove(.denyPublic) - .toList(), - getName: (option) => switch (option) { - .allow => "Allow", - .deny => "Deny", - .denyPublic => "Deny public", - }, - onChanged: specVersionsResponse.maybeWhen( - data: (_) => - (value) => ref - .watch(ClientController.provider.notifier) - .setAccountData( - .new( - type: AccountData.invitePermissionConfigKey, - content: InvitePermissionConfig( - defaultAction: value, - ), - ), - ) - .onError(showError), - orElse: () => null, + builder: (context, ref, _) => + DialogListTile( + icon: Icon(icon), + title: title, + subtitle: Text(description), + initialValue: ref + .watch(AccountDataController.provider) + .invitePermissionConfig + .defaultAction, + options: specVersionsResponse.unstableFeatures.msc4494 + ? DefaultInviteAction.values + : IList( + DefaultInviteAction.values, + ).remove(.denyPublic).toList(), + getName: (option) => switch (option) { + .allow => "Allow", + .deny => "Deny", + .denyPublic => "Deny public", + }, + onChanged: (value) => ref + .watch(ClientController.provider.notifier) + .setAccountData( + .new( + type: AccountData.invitePermissionConfigKey, + content: InvitePermissionConfig( + defaultAction: value, + ), + ), + ) + .onError(showError), ), - ); - }, ), icon: Icons.person_off, ), @@ -164,8 +156,9 @@ class SettingsSectionsController final colorScheme = Theme.of(context).colorScheme; return M3EButton.icon( onPressed: () async { - Navigator.of(context) - .popUntil((route) => route.isFirst); + Navigator.of( + context, + ).popUntil((route) => route.isFirst); await WidgetsBinding.instance.endOfFrame; diff --git a/lib/controllers/spec_versions.dart b/lib/controllers/spec_versions.dart deleted file mode 100644 index 1f879bd..0000000 --- a/lib/controllers/spec_versions.dart +++ /dev/null @@ -1,15 +0,0 @@ -import "package:hooks_riverpod/hooks_riverpod.dart"; -import "package:nexus/controllers/client.dart"; -import "package:nexus/models/spec_versions_response.dart"; - -class SpecVersionsController extends AsyncNotifier { - @override - Future build() => - ref.watch(ClientController.provider.notifier).getSpecVersions(); - - static final provider = - AsyncNotifierProvider.autoDispose< - SpecVersionsController, - SpecVersionsResponse - >(SpecVersionsController.new); -} diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index ed9dc59..a454993 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -170,34 +170,30 @@ class const SettingsPage({super.key}) extends ConsumerWidget { ) : Row( children: [ - MaterialUiCompatibilityBridge( - child: NavigationRailM3E( - type: .alwaysExpand, - trailing: searchBar, - scrollable: true, - sections: sections - .mapTo( - ( - categoryGroup, - categories, - ) => NavigationRailM3ESection( - header: DividerText(categoryGroup), - destinations: categories - .map( - (category) => - NavigationRailM3EDestination( - icon: Icon(category.icon), - label: category.title, - ), - ) - .toList(), - ), - ) - .toList(), - selectedIndex: selected.value, - onDestinationSelected: (value) => - selected.value = value, - ), + NavigationRailM3E( + type: .alwaysExpand, + trailing: searchBar, + scrollable: true, + sections: sections + .mapTo( + (categoryGroup, categories) => + NavigationRailM3ESection( + header: DividerText(categoryGroup), + destinations: categories + .map( + (category) => + NavigationRailM3EDestination( + icon: Icon(category.icon), + label: category.title, + ), + ) + .toList(), + ), + ) + .toList(), + selectedIndex: selected.value, + onDestinationSelected: (value) => + selected.value = value, ), VerticalDivider(), Expanded(