From 4378159b668682f1c763c26136878d7f3732b292 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 10 Sep 2020 14:03:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=BD=A9=E7=A5=A8=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/lottery/lottery_picker_page.dart | 111 +++++++++++++-------- 1 file changed, 71 insertions(+), 40 deletions(-) diff --git a/lib/pages/lottery/lottery_picker_page.dart b/lib/pages/lottery/lottery_picker_page.dart index 1bf6088..94f034b 100644 --- a/lib/pages/lottery/lottery_picker_page.dart +++ b/lib/pages/lottery/lottery_picker_page.dart @@ -312,27 +312,7 @@ class _LotteryPickerPageState extends State { ), Expanded( child: FlatButton( - onPressed: () { - if (lotteryShots == 0) { - showToast(widget.arguments['type'] - ? '至少选6红球1蓝球' - : '至少选5红球2蓝球'); - } else { - _clearAllSelect(); - if (widget.arguments['type']) { - LotteryCartStore.add1Shot( - LotteryType.DOUBLE_LOTTERY, - LotteryCartModel( - type: LotteryType.DOUBLE_LOTTERY, - redBalls: _redBalls, - blueBalls: _blueBalls, - focusedRedBalls: _focusedRedBalls, - focusedBlueBalls: _focusedBlueBalls, - ), - ); - } - } - }, + onPressed: _addShot, shape: RoundedRectangleBorder( borderRadius: BorderRadius.horizontal( left: Radius.circular(rSize(20)), @@ -349,25 +329,7 @@ class _LotteryPickerPageState extends State { ), Expanded( child: FlatButton( - onPressed: () { - helpRandom1Shot() { - _redLotteryViewKey.currentState.random1Shot(); - _blueLotteryViewKey.currentState.random1Shot(); - Future.delayed(Duration(milliseconds: 500), () { - showToast('已帮您机选一注'); - }); - } - - if (widget.arguments['type']) { - if (LotteryCartStore.doubleLotteryModels.length == 0) { - helpRandom1Shot(); - } - } else { - if (LotteryCartStore.bigLotteryModels.length == 0) { - helpRandom1Shot(); - } - } - }, + onPressed: _complateShot, shape: RoundedRectangleBorder( borderRadius: BorderRadius.horizontal( right: Radius.circular(rSize(20)), @@ -401,6 +363,75 @@ class _LotteryPickerPageState extends State { ); } + _addShot() { + if (lotteryShots == 0) { + showToast(widget.arguments['type'] ? '至少选6红球1蓝球' : '至少选5红球2蓝球'); + } else { + _addOneShot(); + _clearAllSelect(); + setState(() {}); + } + } + + _complateShot() { + final bool isDoubleLottery = widget.arguments['type']; + + ///空购物车 + final bool emptyCart = isDoubleLottery + ? LotteryCartStore.doubleLotteryModels.isEmpty + : LotteryCartStore.bigLotteryModels.isEmpty; + + ///未选择 + final bool emptySelect = _redBalls.isEmpty && _blueBalls.isEmpty; + + ///注数为0 + final bool shotZero = lotteryShots == 0; + + if (emptySelect && emptyCart) { + _helpRandom1Shot(); + _addOneShot(); + _clearAllSelect(); + AppRouter.push(context, RouteName.LOTTERY_CART_PAGE, + arguments: {'type': widget.arguments['type']}) + .then((value) => setState(() {})); + } else if (emptySelect && !emptyCart) { + AppRouter.push(context, RouteName.LOTTERY_CART_PAGE, + arguments: {'type': widget.arguments['type']}) + .then((value) => setState(() {})); + } else if (shotZero) { + showToast(widget.arguments['type'] ? '至少选6红球1蓝球' : '至少选5红球2蓝球'); + } else { + _addOneShot(); + _clearAllSelect(); + AppRouter.push(context, RouteName.LOTTERY_CART_PAGE, + arguments: {'type': widget.arguments['type']}) + .then((value) => setState(() {})); + } + } + + _helpRandom1Shot() { + _redLotteryViewKey.currentState.random1Shot(); + _blueLotteryViewKey.currentState.random1Shot(); + Future.delayed(Duration(milliseconds: 500), () { + showToast('已帮您机选一注'); + }); + } + + _addOneShot() { + LotteryCartStore.add1Shot( + widget.arguments['type'] + ? LotteryType.DOUBLE_LOTTERY + : LotteryType.BIG_LOTTERY, + LotteryCartModel( + type: LotteryType.DOUBLE_LOTTERY, + redBalls: _redBalls, + blueBalls: _blueBalls, + focusedRedBalls: _focusedRedBalls, + focusedBlueBalls: _focusedBlueBalls, + ), + ); + } + _countLotteryShot() { lotteryShots = LotteryCartStore.countLotteryBalls( widget.arguments['type']