83 lines
2.3 KiB
Dart
83 lines
2.3 KiB
Dart
|
|
import 'package:badges/badges.dart';
|
|
import 'package:flutter/material.dart';
|
|
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) {
|
|
if (store.state.cartInfos != null && store.state.cartInfos.length > 0) {
|
|
count = 0;
|
|
for (var i = 0; i < store.state.cartInfos.length; i++) {
|
|
if (store.state.cartInfos[i].productList != null && store.state.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,
|
|
);
|
|
}
|
|
}
|
|
} |