From 150b36efaf5791d96d903078ddb33b352303243f Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Fri, 22 Sep 2023 11:04:41 +0700 Subject: [PATCH] fixup! TW-613: Update icon and title when select multi --- lib/pages/settings/settings.dart | 4 +- .../adaptive_layout/adaptive_scaffold.dart | 16 ++++-- .../adaptive_scaffold_view.dart | 51 ++++++------------- .../enum/adaptive_destinations_enum.dart | 46 +++++++++++++++++ 4 files changed, 76 insertions(+), 41 deletions(-) diff --git a/lib/pages/settings/settings.dart b/lib/pages/settings/settings.dart index 5fcfedd731..a105c7cc21 100644 --- a/lib/pages/settings/settings.dart +++ b/lib/pages/settings/settings.dart @@ -166,10 +166,11 @@ class SettingsController extends State with ConnectPageMixin { } } + Client get client => Matrix.of(context).client; + @override void initState() { WidgetsBinding.instance.addPostFrameCallback((_) { - final client = Matrix.of(context).client; profileFuture ??= client.getProfileFromUserId( client.userID!, cache: !profileUpdated, @@ -181,7 +182,6 @@ class SettingsController extends State with ConnectPageMixin { } void checkBootstrap() async { - final client = Matrix.of(context).client; if (!client.encryptionEnabled) return; await client.accountDataLoading; await client.userDeviceKeysLoading; diff --git a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart index 93e5d91bf8..fbf79af045 100644 --- a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart +++ b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart @@ -42,18 +42,25 @@ class AdaptiveScaffoldAppController extends State { }); } + List get destinations => [ + AdaptiveDestinationEnum.contacts, + AdaptiveDestinationEnum.rooms, + AdaptiveDestinationEnum.settings, + ]; + void onDestinationSelected(int index) { - switch (index) { + final destinationType = destinations[index]; + switch (destinationType) { //FIXME: NOW WE SUPPORT FOR ONLY 2 TABS - case 0: + case AdaptiveDestinationEnum.contacts: activeNavigationBar.value = AdaptiveDestinationEnum.contacts; pageController.jumpToPage(index); break; - case 1: + case AdaptiveDestinationEnum.rooms: activeNavigationBar.value = AdaptiveDestinationEnum.rooms; pageController.jumpToPage(index); break; - case 2: + case AdaptiveDestinationEnum.settings: activeNavigationBar.value = AdaptiveDestinationEnum.settings; pageController.jumpToPage(index); break; @@ -100,6 +107,7 @@ class AdaptiveScaffoldAppController extends State { @override Widget build(BuildContext context) => AppScaffoldView( + destinations: destinations, activeRoomId: widget.activeRoomId, activeNavigationBar: activeNavigationBar, pageController: pageController, diff --git a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart index 12b1c40fcb..82e419a5b2 100644 --- a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart +++ b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart @@ -12,11 +12,11 @@ import 'package:fluffychat/widgets/twake_components/twake_navigation_icon/twake_ import 'package:fluffychat/widgets/unread_rooms_badge.dart'; import 'package:flutter/material.dart'; import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:linagora_design_flutter/linagora_design_flutter.dart'; import 'package:matrix/matrix.dart'; class AppScaffoldView extends StatelessWidget { + final List destinations; final ValueNotifier activeNavigationBar; final PageController pageController; final Future fetchOwnProfile; @@ -47,6 +47,7 @@ class AppScaffoldView extends StatelessWidget { required this.onCloseSearchPage, required this.onDestinationSelected, required this.onClientSelected, + required this.destinations, }) : super(key: key ?? scaffoldWithNestedNavigationKey); @override @@ -159,7 +160,8 @@ class AppScaffoldView extends StatelessWidget { children: [ NavigationBar( height: ResponsiveUtils.heightBottomNavigation, - selectedIndex: _getActiveBottomNavigationBarIndex(), + selectedIndex: activeNavigationBar.value + .getActiveBottomNavigationBarIndex(), destinations: getNavigationDestinations(context), onDestinationSelected: onDestinationSelected, ), @@ -172,19 +174,6 @@ class AppScaffoldView extends StatelessWidget { ); } - int _getActiveBottomNavigationBarIndex() { - switch (activeNavigationBar.value) { - case AdaptiveDestinationEnum.contacts: - return 0; - case AdaptiveDestinationEnum.rooms: - return 1; - case AdaptiveDestinationEnum.settings: - return 2; - default: - return 1; - } - } - Widget _primaryNavigationBarBuilder(BuildContext context) { final destinations = getNavigationDestinations(context); @@ -200,25 +189,17 @@ class AppScaffoldView extends StatelessWidget { } List getNavigationDestinations(BuildContext context) { - return [ - NavigationDestination( - icon: const TwakeNavigationIcon( - icon: Icons.contacts_outlined, - ), - label: L10n.of(context)!.contacts, - ), - NavigationDestination( - icon: UnreadRoomsBadge( - filter: (room) => !room.isSpace && !room.isStoryRoom, - ), - label: L10n.of(context)!.chat, - ), - NavigationDestination( - icon: const TwakeNavigationIcon( - icon: Icons.settings, - ), - label: L10n.of(context)!.settings, - ), - ]; + return destinations.map((destination) { + return NavigationDestination( + icon: destination.getIcon() != null + ? TwakeNavigationIcon( + icon: destination.getIcon()!, + ) + : UnreadRoomsBadge( + filter: (room) => !room.isSpace && !room.isStoryRoom, + ), + label: destination.getTitle(context), + ); + }).toList(); } } diff --git a/lib/widgets/layouts/enum/adaptive_destinations_enum.dart b/lib/widgets/layouts/enum/adaptive_destinations_enum.dart index 39bfdc5942..1e7e28c645 100644 --- a/lib/widgets/layouts/enum/adaptive_destinations_enum.dart +++ b/lib/widgets/layouts/enum/adaptive_destinations_enum.dart @@ -1,6 +1,52 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; + enum AdaptiveDestinationEnum { contacts, rooms, settings, search; + + String getTitle(BuildContext context) { + switch (this) { + case AdaptiveDestinationEnum.contacts: + return L10n.of(context)!.contacts; + case AdaptiveDestinationEnum.rooms: + return L10n.of(context)!.chat; + case AdaptiveDestinationEnum.settings: + return L10n.of(context)!.settings; + case AdaptiveDestinationEnum.search: + return ''; + default: + return ''; + } + } + + IconData? getIcon() { + switch (this) { + case AdaptiveDestinationEnum.contacts: + return Icons.contacts_outlined; + case AdaptiveDestinationEnum.rooms: + return null; + case AdaptiveDestinationEnum.settings: + return Icons.settings; + case AdaptiveDestinationEnum.search: + return null; + default: + return null; + } + } + + int getActiveBottomNavigationBarIndex() { + switch (this) { + case AdaptiveDestinationEnum.contacts: + return 0; + case AdaptiveDestinationEnum.rooms: + return 1; + case AdaptiveDestinationEnum.settings: + return 2; + default: + return 1; + } + } }