彩票状态栏颜色适配

添加组合数函数
添加彩票数量计算
master
laiiihz 5 years ago
parent ed56824f93
commit 5c22c9681f

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

@ -2,6 +2,9 @@
/// PLEASE DO NOT EDIT MANUALLY.
class R {
/// ![preview](file:///Users/akufe/Desktop/recook_temp/assets/.DS_Store)
static const String ASSETS__DS_STORE = 'assets/.DS_Store';
/// ![preview](file:///Users/akufe/Desktop/recook_temp/assets/HomeRefreshHeader3.gif)
static const String ASSETS_HOMEREFRESHHEADER3_GIF = 'assets/HomeRefreshHeader3.gif';
@ -347,6 +350,12 @@ class R {
/// ![preview](file:///Users/akufe/Desktop/recook_temp/assets/lottery_redeem/lottery_list.png)
static const String ASSETS_LOTTERY_REDEEM_LOTTERY_LIST_PNG = 'assets/lottery_redeem/lottery_list.png';
/// ![preview](file:///Users/akufe/Desktop/recook_temp/assets/lottery_redeem/random.png)
static const String ASSETS_LOTTERY_REDEEM_RANDOM_PNG = 'assets/lottery_redeem/random.png';
/// ![preview](file:///Users/akufe/Desktop/recook_temp/assets/lottery_redeem/win.png)
static const String ASSETS_LOTTERY_REDEEM_WIN_PNG = 'assets/lottery_redeem/win.png';
/// ![preview](file:///Users/akufe/Desktop/recook_temp/assets/mask_money.png)
static const String ASSETS_MASK_MONEY_PNG = 'assets/mask_money.png';

@ -1,23 +1,48 @@
import 'package:flutter/material.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart';
import 'package:recook/pages/lottery/widget/lottery_ball.dart';
import 'package:recook/pages/lottery/widget/lottery_scaffold.dart';
import 'package:recook/pages/lottery/widget/lottery_view.dart';
import 'package:recook/utils/math/recook_math.dart';
import 'package:recook/widgets/custom_image_button.dart';
import 'package:recook/const/resource.dart';
class LotteryPickerPage extends StatefulWidget {
LotteryPickerPage({Key key}) : super(key: key);
final dynamic arguments;
LotteryPickerPage({Key key, @required this.arguments}) : super(key: key);
@override
_LotteryPickerPageState createState() => _LotteryPickerPageState();
}
class _LotteryPickerPageState extends State<LotteryPickerPage> {
int lotteryShots = 0;
GlobalKey<LotteryViewState> _redLotteryViewKey =
GlobalKey<LotteryViewState>();
GlobalKey<LotteryViewState> _blueLotteryViewKey =
GlobalKey<LotteryViewState>();
List<int> _redBalls = [];
List<int> _blueBalls = [];
@override
Widget build(BuildContext context) {
return LotteryScaffold(
red: true,
whiteBg: true,
appBarBottom: PreferredSize(
child: Container(
color: Color(0xFFFEF8E2),
height: rSize(36),
width: double.infinity,
),
preferredSize: Size.fromHeight(rSize(36)),
),
title: Column(
children: [
Text(
'双色球',
widget.arguments['type'] ? '双色球' : '大乐透',
style: TextStyle(
color: Colors.white,
fontSize: rSP(18),
@ -52,7 +77,187 @@ class _LotteryPickerPageState extends State<LotteryPickerPage> {
),
),
],
body: SizedBox(),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.symmetric(
vertical: rSize(10),
horizontal: rSize(16),
),
child: Text(
'选中号码两次设胆',
style: TextStyle(
color: Color(0xFF666666),
fontSize: rSP(12),
),
),
),
Expanded(
child: ListView(
children: [
LotteryView(
colorType: LotteryColorType.RED,
key: _redLotteryViewKey,
type: widget.arguments['type']
? LotteryType.DOUBLE_LOTTERY
: LotteryType.BIG_LOTTERY,
onSelect: (selected) {
_redBalls = selected;
_countLotteryShot();
},
),
SizedBox(height: rSize(15)),
LotteryView(
onSelect: (selected) {
_blueBalls = selected;
_countLotteryShot();
},
key: _blueLotteryViewKey,
colorType: LotteryColorType.BLUE,
type: widget.arguments['type']
? LotteryType.DOUBLE_LOTTERY
: LotteryType.BIG_LOTTERY,
),
],
),
),
Padding(
padding: EdgeInsets.only(left: rSize(16)),
child: Text(
'快速选择',
style: TextStyle(
color: Color(0xFF666666),
fontSize: rSP(12),
),
),
),
Container(
padding: EdgeInsets.only(
left: rSize(16),
right: rSize(16),
bottom: rSize(24),
top: rSize(10),
),
child: Row(
children: [
_buildFastCard('机选1注', () {
_redLotteryViewKey.currentState.random1Shot();
_blueLotteryViewKey.currentState.random1Shot();
}),
SizedBox(width: rSize(16)),
_buildFastCard('机选5注', () {}),
SizedBox(width: rSize(16)),
_buildFastCard('后区全包', () {
_blueLotteryViewKey.currentState.selectAllBlue();
}),
],
),
),
],
),
bottomNavi: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
blurRadius: rSize(4),
offset: Offset(0, rSize(2)),
)
],
),
child: SafeArea(
bottom: true,
top: false,
child: Container(
height: rSize(48),
width: double.infinity,
child: Row(
children: [
SizedBox(width: 5),
CustomImageButton(
padding: EdgeInsets.symmetric(
horizontal: rSize(10),
),
onPressed: () {
_redLotteryViewKey.currentState.clear();
_blueLotteryViewKey.currentState.clear();
},
child: Image.asset(
R.ASSETS_LOTTERY_REDEEM_LOTTERY_DELETE_PNG,
width: rSize(16),
height: rSize(16),
),
),
VerticalDivider(
indent: rSize(16),
endIndent: rSize(16),
width: 1,
thickness: 1,
color: Color(0xFFCCCCCC),
),
SizedBox(width: rSize(10)),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${lotteryShots * 2}瑞币或$lotteryShots\彩票券',
style: TextStyle(
fontSize: rSP(12),
color: Color(0xFF666666),
),
),
Text(
'$lotteryShots\',
style: TextStyle(
fontSize: rSP(12),
color: Color(0xFF666666),
),
),
],
),
],
),
),
),
),
);
}
_countLotteryShot() {
if (widget.arguments['type']) {
lotteryShots = RecookMath.combination(6, _redBalls.length) *
RecookMath.combination(1, _blueBalls.length);
} else {
lotteryShots = RecookMath.combination(5, _redBalls.length) *
RecookMath.combination(2, _blueBalls.length);
}
setState(() {});
}
_buildFastCard(String title, VoidCallback onTap) {
return Expanded(
child: CustomImageButton(
onPressed: onTap,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFFFF4F4),
borderRadius: BorderRadius.circular(rSize(4)),
),
height: rSize(36),
child: Text(
title,
style: TextStyle(
color: Color(0xFFE02020),
fontSize: rSP(14),
),
),
),
),
);
}
}

@ -62,7 +62,8 @@ class _RedeemLotteryPageState extends State<RedeemLotteryPage> {
return CustomImageButton(
onPressed: () {
AppRouter.push(context, RouteName.LOTTERY_PICKER_PAGE);
AppRouter.push(context, RouteName.LOTTERY_PICKER_PAGE,
arguments: {'type': type == LotteryType.DOUBLE_LOTTERY});
},
child: Container(
padding: EdgeInsets.all(rSize(16)),

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:recook/constants/styles.dart';
import 'package:recook/widgets/custom_app_bar.dart';
import 'package:recook/widgets/recook_back_button.dart';
@ -6,9 +7,11 @@ import 'package:recook/widgets/recook_back_button.dart';
class LotteryScaffold extends StatefulWidget {
final dynamic title;
final bool red;
final bool whiteBg;
final List<Widget> actions;
final Widget body;
final Widget bottomNavi;
final PreferredSizeWidget appBarBottom;
LotteryScaffold({
Key key,
@required this.title,
@ -16,6 +19,8 @@ class LotteryScaffold extends StatefulWidget {
this.actions,
this.body,
this.bottomNavi,
this.appBarBottom,
this.whiteBg = false,
}) : super(key: key);
@override
@ -26,9 +31,13 @@ class _LotteryScaffoldState extends State<LotteryScaffold> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFF9F9FB),
backgroundColor: widget.whiteBg ? Colors.white : Color(0xFFF9F9FB),
appBar: CustomAppBar(
bottom: widget.appBarBottom,
elevation: 0,
themeData: AppBarTheme(
brightness: widget.red ? Brightness.dark : Brightness.light,
),
title: widget.title is String
? Text(
widget.title,

@ -0,0 +1,178 @@
import 'package:flutter/material.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart';
import 'package:recook/pages/lottery/widget/lottery_ball.dart';
import 'package:recook/widgets/custom_image_button.dart';
class LotteryView extends StatefulWidget {
final LotteryType type;
final LotteryColorType colorType;
final Function(List<int> selected) onSelect;
LotteryView({
Key key,
this.type = LotteryType.DOUBLE_LOTTERY,
this.colorType = LotteryColorType.RED,
this.onSelect,
}) : super(key: key);
@override
LotteryViewState createState() => LotteryViewState();
}
class LotteryViewState extends State<LotteryView> {
int lotterySize;
List<SingleBox> _lotteryBoxes = [];
List<SingleBox> _selectedBoxes = [];
List<SingleBox> _focusedBoxes = [];
@override
void initState() {
super.initState();
lotterySize = widget.type == LotteryType.DOUBLE_LOTTERY
? widget.colorType == LotteryColorType.RED ? 33 : 16
: widget.colorType == LotteryColorType.RED ? 35 : 12;
for (int i = 1; i <= lotterySize; i++) {
_lotteryBoxes.add(SingleBox(i));
}
}
selectAllBlue() {
_selectedBoxes.clear();
_lotteryBoxes.forEach((element) {
_selectedBoxes.add(element);
});
setState(() {});
}
clear() {
_selectedBoxes.clear();
_focusedBoxes.clear();
setState(() {});
}
random1Shot() {
_selectedBoxes.clear();
_focusedBoxes.clear();
List<SingleBox> temp = [];
_lotteryBoxes.forEach((element) => temp.add(element));
int randomShotsSize = widget.type == LotteryType.DOUBLE_LOTTERY
? widget.colorType == LotteryColorType.RED ? 6 : 1
: widget.colorType == LotteryColorType.RED ? 5 : 2;
for (int i = 0; i < randomShotsSize; i++) {
temp.shuffle();
_selectedBoxes.add(temp[0]);
temp.removeAt(0);
}
setState(() {});
//
// if (limitSize < _focusedBoxes.length) {
// showToast(
// '${widget.colorType == LotteryColorType.RED ? '红球' : '蓝球'}胆球数过多');
// } else {
// _selectedBoxes.clear();
// List<SingleBox> temp = [];
// _lotteryBoxes.forEach((element) => temp.add(element));
// _focusedBoxes.forEach((element) {
// _selectedBoxes.add(element);
// temp.remove(element);
// });
// int randomShotsSize = widget.type == LotteryType.DOUBLE_LOTTERY
// ? widget.colorType == LotteryColorType.RED ? 6 : 1
// : widget.colorType == LotteryColorType.RED ? 5 : 2;
// for (int i = 0; i < (randomShotsSize - _focusedBoxes.length); i++) {
// temp.shuffle();
// _selectedBoxes.add(temp[0]);
// temp.removeAt(0);
// }
// setState(() {});
// }
}
@override
Widget build(BuildContext context) {
return GridView.count(
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 7,
shrinkWrap: true,
crossAxisSpacing: rSize(16),
mainAxisSpacing: rSize(16),
childAspectRatio: 1,
padding: EdgeInsets.symmetric(
horizontal: rSize(16),
),
children: _lotteryBoxes.map((e) => _buildLotteryBox(e)).toList(),
);
}
Widget _buildLotteryBox(SingleBox box) {
bool selected = _selectedBoxes.indexOf(box) != -1;
bool focused = _focusedBoxes.indexOf(box) != -1;
return CustomImageButton(
padding: EdgeInsets.zero,
onPressed: () {
if (!selected) {
_selectedBoxes.add(box);
} else if (selected && !focused) {
_focusedBoxes.add(box);
} else {
_selectedBoxes.remove(box);
_focusedBoxes.remove(box);
}
widget.onSelect(
_selectedBoxes.map((e) => e.value).toList(),
);
setState(() {});
},
child: Container(
decoration: BoxDecoration(
color: selected
? widget.colorType == LotteryColorType.RED
? Color(0xFFE02020)
: Color(0xFF0E89E7)
: Colors.white,
borderRadius: BorderRadius.circular(rSize(18)),
border: Border.all(
width: rSize(1),
color: widget.colorType == LotteryColorType.RED
? Color(0xFFE02020)
: Color(0xFF0E89E7),
),
),
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
box.displayStr,
style: TextStyle(
fontSize: rSP(16),
color: selected
? Colors.white
: widget.colorType == LotteryColorType.RED
? Color(0xFFE02020)
: Color(0xFF0E89E7),
),
),
focused
? Text(
'',
style: TextStyle(
height: 1,
color: Colors.white,
fontSize: rSP(14),
),
)
: SizedBox(),
],
),
),
);
}
}
class SingleBox {
int value;
String get displayStr => (value < 10) ? "0$value" : "$value";
SingleBox(this.value);
}

@ -301,6 +301,7 @@ class RouteName {
//
///
static const String REDEEM_LOTTERY_PAGE = "/ReddemLotteryPage";
///
static const String LOTTERY_PICKER_PAGE = "/LotteryPickerPage";
}
@ -599,13 +600,15 @@ final Map<String, RouteBuilder> _routes = {
RouteName.USER_INVOICE_USUALLY_USED: (contex, {arguments}) =>
InvoiceUsuallyUsedPage(),
RouteName.USER_INVOICE_ADD_TITLE: (contex, {arguments}) =>
InvoiceAddTitlePage(arguments:arguments),
InvoiceAddTitlePage(arguments: arguments),
RouteName.USER_INVOICE_DETAIL_INFOMATION: (contex, {arguments}) =>
InvoiceDetailInfomationPage(
arguments: arguments,
),
RouteName.REDEEM_LOTTERY_PAGE: (context, {arguments}) => RedeemLotteryPage(),
RouteName.LOTTERY_PICKER_PAGE:(context,{arguments})=>LotteryPickerPage(),
RouteName.LOTTERY_PICKER_PAGE: (context, {arguments}) => LotteryPickerPage(
arguments: arguments,
),
};
///

@ -0,0 +1,20 @@
class RecookMath {
///
///
///
///
///
///[Stackoverflow](https://stackoverflow.com/questions/12130094/optimizing-calculating-combination-and-avoiding-overflows)
///
///[blog](https://blog.plover.com/math/choose.html)
static int combination(int k, int n) {
int r = 1;
int d;
if (k > n) return 0;
for (d = 1; d <= k; d++) {
r *= n--;
r = (r / d).floor();
}
return r;
}
}
Loading…
Cancel
Save