You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
4.3 KiB
Dart
131 lines
4.3 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
|
|
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
|
|
import 'package:mohem_flutter_app/ui/mazaya/mazaya_discover_screen.dart';
|
|
import 'package:mohem_flutter_app/ui/mazaya/saved_retailers_screen.dart';
|
|
import 'package:mohem_flutter_app/ui/profile/family_members.dart';
|
|
|
|
enum MazayaTab { discover, saved, myFamily }
|
|
|
|
// Shared bottom nav for the Mazaya module (Discover / Saved / My Family). Each tab is its own
|
|
// screen, swapped in with zero-duration transition (see _onTabTapped) so switching tabs feels
|
|
// instant rather than like a new screen opening - not an IndexedStack shell, since each tab still
|
|
// needs to reload its own data fresh on every switch, not preserve state across tabs.
|
|
class MazayaBottomNav extends StatelessWidget {
|
|
final MazayaTab currentTab;
|
|
|
|
const MazayaBottomNav({Key? key, required this.currentTab}) : super(key: key);
|
|
|
|
static const Color _activeColor = Color(0xFF147D6B);
|
|
static const Color _inactiveColor = Color(0xFF78817F);
|
|
|
|
void _onTabTapped(BuildContext context, MazayaTab tab) {
|
|
if (tab == currentTab) return;
|
|
Widget targetScreen;
|
|
RouteSettings? settings;
|
|
switch (tab) {
|
|
case MazayaTab.discover:
|
|
targetScreen = const MazayaDiscoverScreen();
|
|
break;
|
|
case MazayaTab.saved:
|
|
targetScreen = const SavedRetailersScreen();
|
|
break;
|
|
case MazayaTab.myFamily:
|
|
targetScreen = const FamilyMembers();
|
|
settings = const RouteSettings(
|
|
arguments: <String, dynamic>{'fromMazaya': true},
|
|
);
|
|
break;
|
|
}
|
|
Navigator.pushReplacement(
|
|
context,
|
|
PageRouteBuilder<void>(
|
|
settings: settings,
|
|
pageBuilder:
|
|
(
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
) => targetScreen,
|
|
transitionDuration: Duration.zero,
|
|
reverseTransitionDuration: Duration.zero,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildItem(
|
|
BuildContext context, {
|
|
required MazayaTab tab,
|
|
required String svgAsset,
|
|
required String label,
|
|
}) {
|
|
bool isActive = tab == currentTab;
|
|
return Expanded(
|
|
child: InkWell(
|
|
onTap: () => _onTabTapped(context, tab),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
SvgPicture.asset(
|
|
svgAsset,
|
|
width: 22,
|
|
height: 22,
|
|
colorFilter: ColorFilter.mode(
|
|
isActive ? _activeColor : _inactiveColor,
|
|
BlendMode.srcIn,
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
label.toText11(
|
|
weight: isActive ? FontWeight.w600 : FontWeight.w400,
|
|
color: isActive ? _activeColor : _inactiveColor,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SafeArea(
|
|
top: false,
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border(top: BorderSide(color: Color(0xFFE8EAE4))),
|
|
),
|
|
padding: const EdgeInsets.only(top: 13, bottom: 9),
|
|
child: Row(
|
|
children: <Widget>[
|
|
_buildItem(
|
|
context,
|
|
tab: MazayaTab.discover,
|
|
svgAsset: "assets/icons/mazaya_compass.svg",
|
|
label: LocaleKeys.discover.tr(),
|
|
),
|
|
_buildItem(
|
|
context,
|
|
tab: MazayaTab.saved,
|
|
svgAsset: "assets/icons/mazaya_heart_outline.svg",
|
|
label: LocaleKeys.saved.tr(),
|
|
),
|
|
// My Family lets the account holder manage their dependents' Mazaya access - not
|
|
// applicable (and not shown) when a dependent is the one logged in.
|
|
if (!ApiConsts.isDependetLogin)
|
|
_buildItem(
|
|
context,
|
|
tab: MazayaTab.myFamily,
|
|
svgAsset: "assets/icons/mazaya_user_round.svg",
|
|
label: LocaleKeys.myFamily.tr(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|