Badge unseenSalesCount di tab Riwayat (admin only), reset saat tab dibuka
This commit is contained in:
@@ -35,7 +35,7 @@ class _HomePageState extends State<HomePage> {
|
||||
return screens;
|
||||
}
|
||||
|
||||
List<BottomNavigationBarItem> _navItemsForRole(String? role) {
|
||||
List<BottomNavigationBarItem> _navItemsForRole(String? role, AppState state) {
|
||||
final items = <BottomNavigationBarItem>[
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.point_of_sale),
|
||||
@@ -48,8 +48,12 @@ class _HomePageState extends State<HomePage> {
|
||||
icon: Icon(Icons.inventory_2),
|
||||
label: 'Produk',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.receipt_long),
|
||||
BottomNavigationBarItem(
|
||||
icon: Badge(
|
||||
isLabelVisible: state.unseenSalesCount > 0,
|
||||
label: Text('${state.unseenSalesCount}'),
|
||||
child: const Icon(Icons.receipt_long),
|
||||
),
|
||||
label: 'Riwayat',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
@@ -76,7 +80,7 @@ class _HomePageState extends State<HomePage> {
|
||||
Widget build(BuildContext context) {
|
||||
final state = context.watch<AppState>();
|
||||
final screens = _screensForRole(state.userRole);
|
||||
final navItems = _navItemsForRole(state.userRole);
|
||||
final navItems = _navItemsForRole(state.userRole, state);
|
||||
|
||||
final safeIndex = _index >= screens.length ? 0 : _index;
|
||||
|
||||
@@ -109,7 +113,14 @@ class _HomePageState extends State<HomePage> {
|
||||
bottomNavigationBar: navItems.length >= 2
|
||||
? BottomNavigationBar(
|
||||
currentIndex: safeIndex,
|
||||
onTap: (i) => setState(() => _index = i),
|
||||
onTap: (i) {
|
||||
setState(() => _index = i);
|
||||
// Reset badge saat tab Riwayat dibuka.
|
||||
final riwayatIdx = state.userRole == 'admin' ? 2 : 1;
|
||||
if (i == riwayatIdx) {
|
||||
context.read<AppState>().markSalesSeen();
|
||||
}
|
||||
},
|
||||
items: navItems,
|
||||
)
|
||||
: null,
|
||||
|
||||
Reference in New Issue
Block a user