Files
enaklo-flutter/lib/presentation/pages/main/widgets/bottom_navbar.dart
T

104 lines
2.9 KiB
Dart
Raw Normal View History

2025-08-27 18:51:14 +07:00
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import '../../../../common/theme/theme.dart';
2025-08-27 18:51:14 +07:00
class MainBottomNavbar extends StatelessWidget {
final TabsRouter tabsRouter;
final VoidCallback onPayTap;
const MainBottomNavbar({
super.key,
required this.tabsRouter,
required this.onPayTap,
});
/// Slot tengah hanya tempat label tombol Bayar; lingkarannya
/// [MainPayButton] yang menempel di atas navbar.
static const int _payIndex = 2;
2025-08-27 18:51:14 +07:00
@override
Widget build(BuildContext context) {
final activeIndex = tabsRouter.activeIndex;
2025-08-27 18:51:14 +07:00
return BottomNavigationBar(
currentIndex: activeIndex >= _payIndex ? activeIndex + 1 : activeIndex,
2025-08-27 18:51:14 +07:00
onTap: (index) {
if (index == _payIndex) {
onPayTap();
return;
}
tabsRouter.setActiveIndex(index > _payIndex ? index - 1 : index);
2025-08-27 18:51:14 +07:00
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
tooltip: 'Home',
),
2026-01-16 12:26:06 +07:00
// BottomNavigationBarItem(
// icon: Icon(Icons.discount),
// label: 'Voucher',
// tooltip: 'Voucher',
// ),
2025-08-27 18:51:14 +07:00
BottomNavigationBarItem(
icon: Icon(Icons.list),
label: 'Pesanan',
tooltip: 'Pesanan',
),
BottomNavigationBarItem(
icon: SizedBox(height: 24),
label: 'Bayar',
tooltip: 'Bayar di kasir',
),
BottomNavigationBarItem(
icon: Icon(Icons.groups),
label: 'Community',
tooltip: 'Community',
),
2025-08-27 18:51:14 +07:00
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profil',
tooltip: 'Profil',
),
],
);
}
}
/// Seperti [FloatingActionButtonLocation.centerDocked], tapi tombolnya lebih
/// menonjol ke atas supaya tidak menempel ke label "Bayar".
class MainPayButtonLocation extends StandardFabLocation
with FabCenterOffsetX, FabDockedOffsetY {
const MainPayButtonLocation();
static const double _raise = 10;
@override
double getOffsetY(
ScaffoldPrelayoutGeometry scaffoldGeometry,
double adjustment,
) => super.getOffsetY(scaffoldGeometry, adjustment) - _raise;
}
/// Tombol bulat di tengah navbar, dipasang di [MainPayButtonLocation].
class MainPayButton extends StatelessWidget {
final VoidCallback onPressed;
const MainPayButton({super.key, required this.onPressed});
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: onPressed,
// Halaman tab (mis. Community) juga punya FAB; tanpa hero supaya tag
// default tidak bentrok saat pindah halaman.
heroTag: null,
tooltip: 'Bayar di kasir',
elevation: 4,
backgroundColor: AppColor.primary,
foregroundColor: AppColor.white,
shape: const CircleBorder(),
child: const Icon(Icons.qr_code_scanner_rounded, size: 28),
);
}
}