Skip to content

Commit

Permalink
fixup! TW-613: Update icon and title when select multi
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Sep 22, 2023
1 parent 718b5ec commit 150b36e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 41 deletions.
4 changes: 2 additions & 2 deletions lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,11 @@ class SettingsController extends State<Settings> 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,
Expand All @@ -181,7 +182,6 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
}

void checkBootstrap() async {
final client = Matrix.of(context).client;
if (!client.encryptionEnabled) return;
await client.accountDataLoading;
await client.userDeviceKeysLoading;
Expand Down
16 changes: 12 additions & 4 deletions lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,25 @@ class AdaptiveScaffoldAppController extends State<AdaptiveScaffoldApp> {
});
}

List<AdaptiveDestinationEnum> 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;
Expand Down Expand Up @@ -100,6 +107,7 @@ class AdaptiveScaffoldAppController extends State<AdaptiveScaffoldApp> {

@override
Widget build(BuildContext context) => AppScaffoldView(
destinations: destinations,
activeRoomId: widget.activeRoomId,
activeNavigationBar: activeNavigationBar,
pageController: pageController,
Expand Down
51 changes: 16 additions & 35 deletions lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdaptiveDestinationEnum> destinations;
final ValueNotifier<AdaptiveDestinationEnum> activeNavigationBar;
final PageController pageController;
final Future<Profile?> fetchOwnProfile;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -159,7 +160,8 @@ class AppScaffoldView extends StatelessWidget {
children: [
NavigationBar(
height: ResponsiveUtils.heightBottomNavigation,
selectedIndex: _getActiveBottomNavigationBarIndex(),
selectedIndex: activeNavigationBar.value
.getActiveBottomNavigationBarIndex(),
destinations: getNavigationDestinations(context),
onDestinationSelected: onDestinationSelected,
),
Expand All @@ -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);

Expand All @@ -200,25 +189,17 @@ class AppScaffoldView extends StatelessWidget {
}

List<NavigationDestination> 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();
}
}
46 changes: 46 additions & 0 deletions lib/widgets/layouts/enum/adaptive_destinations_enum.dart
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 150b36e

Please sign in to comment.