cart_count.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_note/provide/cart_provide.dart';
  3. class CartCountWidget extends StatelessWidget {
  4. final int count;
  5. final String goodsId;
  6. final CartProvide cartProvide;
  7. CartCountWidget({Key key, this.count, this.goodsId, this.cartProvide})
  8. : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. width: 120.0,
  13. height: 30.0,
  14. decoration: ShapeDecoration(
  15. shape: RoundedRectangleBorder(
  16. borderRadius: BorderRadius.all(Radius.circular(2.0)),
  17. side: BorderSide(color: Colors.black54)),
  18. ),
  19. child: Row(
  20. crossAxisAlignment: CrossAxisAlignment.center,
  21. children: [
  22. // 减值操作,数量为 1 停止
  23. Expanded(
  24. child: InkWell(
  25. onTap: count == 1
  26. ? null
  27. : () => cartProvide.increaseOrReduceOperation(goodsId, false),
  28. child: DecoratedBox(
  29. decoration: BoxDecoration(
  30. border: Border(
  31. right: BorderSide(color: Colors.black54, width: 1.0)),
  32. ),
  33. child: Center(
  34. child: Text('-',
  35. style:
  36. TextStyle(fontSize: 16.0, color: Colors.black)))),
  37. ),
  38. ),
  39. Expanded(
  40. child: Center(
  41. child: Text('$count',
  42. style: TextStyle(fontSize: 14.0, color: Colors.black))),
  43. flex: 2),
  44. // 加值操作
  45. Expanded(
  46. child: InkWell(
  47. onTap: () => cartProvide.increaseOrReduceOperation(goodsId, true),
  48. child: DecoratedBox(
  49. decoration: BoxDecoration(
  50. border: Border(
  51. left: BorderSide(color: Colors.black54, width: 1.0)),
  52. ),
  53. child: Center(
  54. child: Text('+',
  55. style:
  56. TextStyle(fontSize: 16.0, color: Colors.black)))),
  57. ),
  58. )
  59. ],
  60. ),
  61. );
  62. }
  63. }