Files
flutter_wisetronic/lib/widgets/mobile/MobileBottomNav.dart
peima 88dd90ed7c phase3(critical-path): home page chain null-safe
home.dart + desktop/mobile navigation, carousels, index content widgets,
customers_logo, appbar_menu, navigation_drawer, MobileBottomNav, double_back.
Fixes: Key? params, nullable State fields, Scrollbar thumbVisibility,
ModalRoute.of()?, badges hide Badge, cartInfos local promotion.
2026-07-24 13:42:03 +08:00

84 lines
2.3 KiB
Dart

import 'package:badges/badges.dart';
import 'package:flutter/material.dart' hide Badge;
import '../../constants.dart';
import '../../generated/l10n.dart';
import '../../routes.dart';
import '../../store/store.dart';
class MobileBottomNav extends StatelessWidget {
final int currentIndex;
int count = 0;
MobileBottomNav({int currentIndex = 0}) : currentIndex = currentIndex;
@override
Widget build(BuildContext context) {
final cartInfos = store.state.cartInfos;
if (cartInfos != null && cartInfos.length > 0) {
count = 0;
for (var i = 0; i < cartInfos.length; i++) {
if (cartInfos[i].productList != null && cartInfos[i].productList!.length > 0) {
count += 1;
}
}
} else {
count = 0;
}
return new BottomNavigationBar(
onTap: (index) => _go(context, index),
currentIndex: currentIndex,
fixedColor: Theme.of(context).primaryColor,
type: BottomNavigationBarType.fixed,
items: <BottomNavigationBarItem>[
new BottomNavigationBarItem(
icon: new Icon(Icons.store),
label: S.of(context).home
),
new BottomNavigationBarItem(
icon: count > 0 ? Badge(
badgeContent: Text('${count}', style: TextStyle(fontSize: 11.0, color: Colors.white),),
child: new Icon(Icons.shopping_basket),
) : Icon(Icons.shopping_basket),
label: S.of(context).shop
),
new BottomNavigationBarItem(
icon: new Icon(Icons.support_agent),
label: S.of(context).support
),
new BottomNavigationBarItem(
icon: new Icon(Icons.person),
label: S.of(context).me
)
]
);
}
_go(BuildContext context, int index) {
if (index == currentIndex) return;
String path = '';
switch(index) {
case 0:
path = '/';
break;
case 1:
path = '/shop';
break;
case 2:
path = '/my-support/${Constants.BUSINESS_ID}';
break;
case 3:
path = '/me';
break;
}
if (path.length > 0) {
print('go to: $path');
Routes.router.navigateTo(
context,
path,
replace: false,
);
}
}
}