79 lines
2.0 KiB
Dart
79 lines
2.0 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../events/eventbus.dart';
|
|
import '../../events/events.dart';
|
|
import '../../models/business.dart';
|
|
import '../../models/cart_info.dart';
|
|
import '../../store/store.dart';
|
|
import '../../utils/utils.dart';
|
|
|
|
class ShoppingCartWidget extends StatefulWidget {
|
|
final Business business;
|
|
final Function onTap;
|
|
|
|
ShoppingCartWidget({@required this.business, this.onTap});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => ShoppingCartWidgetState();
|
|
}
|
|
|
|
class ShoppingCartWidgetState extends State<ShoppingCartWidget> {
|
|
CartInfo cartInfo;
|
|
double totalPrice = 0.0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
totalPrice = 0.0;
|
|
cartInfo = Utils.getCartInfoByBusiness(store.state.cartInfos, widget.business);
|
|
if (cartInfo != null && cartInfo.businessInfo.id == widget.business.id) {
|
|
totalPrice = cartInfo.getTotalPrice();
|
|
}
|
|
Row row = Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.only(left: 16.0, right: 4.0, top: 8.0),
|
|
child: Icon(
|
|
Icons.shopping_basket_outlined,
|
|
size: 24,
|
|
color: Colors.blue,
|
|
),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.only(left: 4.0, right: 16.0, top: 8.0),
|
|
child: Text(
|
|
'\$${totalPrice.toStringAsFixed(2)}',
|
|
style: TextStyle(
|
|
color: totalPrice > 0 ? Colors.red : Colors.black45,
|
|
fontWeight: totalPrice > 0 ? FontWeight.bold : FontWeight.normal,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
return MouseRegion(
|
|
cursor: SystemMouseCursors.click,
|
|
child: GestureDetector(
|
|
child: Container(
|
|
child: row,
|
|
width: 160.0,
|
|
),
|
|
onTap: widget.onTap,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
eventBus.on<OnCartInfoUpdated>().listen((event) {
|
|
if (mounted) {
|
|
setState(() {
|
|
|
|
});
|
|
}
|
|
});
|
|
}
|
|
} |