2024-11-13 16:08:09 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2024-11-08 16:09:46 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-11-13 16:08:09 +00:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:surface/providers/navigation.dart';
|
2024-11-08 16:09:46 +00:00
|
|
|
|
|
|
|
class AppBottomNavigationBar extends StatefulWidget {
|
|
|
|
const AppBottomNavigationBar({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AppBottomNavigationBar> createState() => _AppBottomNavigationBarState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AppBottomNavigationBarState extends State<AppBottomNavigationBar> {
|
2024-11-13 16:08:09 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
context
|
|
|
|
.read<NavigationProvider>()
|
|
|
|
.autoDetectIndex(GoRouter.maybeOf(context));
|
|
|
|
});
|
|
|
|
}
|
2024-11-08 16:09:46 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-13 16:08:09 +00:00
|
|
|
final nav = context.watch<NavigationProvider>();
|
|
|
|
|
|
|
|
return ListenableBuilder(
|
|
|
|
listenable: nav,
|
|
|
|
builder: (context, _) {
|
|
|
|
if (!nav.isIndexInRange(0, nav.pinnedDestinationCount)) {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
|
|
|
|
final destinations = [
|
|
|
|
...nav.destinations.where((ele) => ele.isPinned),
|
|
|
|
];
|
|
|
|
|
|
|
|
return BottomNavigationBar(
|
|
|
|
currentIndex: nav.getIndexInRange(0, nav.pinnedDestinationCount),
|
|
|
|
type: BottomNavigationBarType.fixed,
|
|
|
|
showUnselectedLabels: false,
|
|
|
|
items: destinations.map((ele) {
|
|
|
|
return BottomNavigationBarItem(
|
|
|
|
icon: ele.icon,
|
|
|
|
label: ele.label.tr(),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
onTap: (idx) {
|
|
|
|
nav.setIndex(idx);
|
|
|
|
GoRouter.of(context).goNamed(destinations[idx].screen);
|
|
|
|
},
|
2024-11-08 16:09:46 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|