YSPayKeybord.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:ysairplane2/tools/YSNetWorking.dart';
  4. import 'package:ysairplane2/tools/YSTools.dart';
  5. Widget ysPayKeybord(BuildContext context,ValueSetter password,String title,String price){
  6. List _passArray = [];
  7. return StatefulBuilder(
  8. builder: (BuildContext context, StateSetter setState) {
  9. return Stack(
  10. children: [
  11. Container(
  12. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(200),left: hsp(50)),
  13. width: MediaQuery.of(context).size.width-hsp(100),
  14. height: title.length>18?hsp(550):hsp(500),
  15. decoration: BoxDecoration(
  16. color: Colors.white,
  17. borderRadius: BorderRadius.all(Radius.circular(10))
  18. ),
  19. padding: EdgeInsets.all(hsp(30)),
  20. child: Column(
  21. children: [
  22. Row(
  23. children: [
  24. Container(width: hsp(40),),
  25. Text('请输入支付密码',style: TextStyle(fontWeight: FontWeight.bold,fontSize: zsp(36),color: Color(0xFF333333)),),
  26. GestureDetector(
  27. onTap: (){
  28. Navigator.pop(context);
  29. },
  30. child: Icon(Icons.close,size: hsp(40),color: Color(0xFF333333),),
  31. )
  32. ],
  33. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  34. ),
  35. Container(
  36. margin: EdgeInsets.only(top: hsp(80),bottom: hsp(10)),
  37. child: Text('$title',style: TextStyle(fontWeight: FontWeight.bold,fontSize: zsp(34),color: Color(0xFF333333)),textAlign: TextAlign.center,),
  38. ),
  39. RichText(
  40. text: TextSpan(
  41. text: '付款 ',
  42. style: TextStyle(fontWeight: FontWeight.bold,fontSize: zsp(34),color: Color(0xFF333333)),
  43. children: [
  44. TextSpan(
  45. text: '$price',
  46. style: TextStyle(color: Color(0xFFFF4747))
  47. ),
  48. TextSpan(
  49. text: '元'
  50. )
  51. ]
  52. ),
  53. ),
  54. Container(
  55. width: MediaQuery.of(context).size.width-hsp(220),
  56. height: hsp(100),
  57. margin: EdgeInsets.only(top: hsp(40)),
  58. decoration: BoxDecoration(
  59. border: Border.all(color: Color(0xFF9A9A9A),width: 1),
  60. borderRadius: BorderRadius.all(Radius.circular(5))
  61. ),
  62. child: ListView.separated(
  63. itemBuilder: (context,index){
  64. return Container(
  65. height: hsp(100),
  66. width: (MediaQuery.of(context).size.width-hsp(220)-6)/6,
  67. child: Container(
  68. height: hsp(20),
  69. width: hsp(20),
  70. decoration: BoxDecoration(
  71. color: index<_passArray.length?Colors.black:Colors.transparent,
  72. borderRadius: BorderRadius.all(Radius.circular(50))
  73. ),
  74. ),
  75. alignment: Alignment.center,
  76. );
  77. },
  78. separatorBuilder: (context,index){
  79. return Container(width: 1,color: Color(0xFF9A9A9A),height: hsp(100),);
  80. },
  81. itemCount: 6,
  82. padding: EdgeInsets.all(0),
  83. scrollDirection: Axis.horizontal,
  84. ),
  85. ),
  86. ],
  87. ),
  88. ),
  89. Container(
  90. margin: EdgeInsets.only(top: MediaQuery.of(context).size.height-hsp(432)-20),
  91. width: MediaQuery.of(context).size.width,
  92. height: hsp(432),
  93. child: GridView.builder(
  94. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  95. crossAxisCount: 3,
  96. mainAxisSpacing: 1,
  97. crossAxisSpacing: 1,
  98. childAspectRatio: ((MediaQuery.of(context).size.width-2)/3)/((hsp(432)-3)/4)
  99. ),
  100. itemBuilder: (context, index) {
  101. return GestureDetector(
  102. onTap: (){
  103. if(index==9){
  104. if(_passArray.length>0){
  105. _passArray.removeAt(_passArray.length-1);
  106. }
  107. setState(() {});
  108. }else if(index==11){
  109. if(_passArray.length==6){
  110. Navigator.pop(context);
  111. String text = _passArray.join('');
  112. password(text);
  113. }else{
  114. ysFlutterToast(context, '支付密码为6位数字');
  115. }
  116. }else{
  117. if(_passArray.length<6){
  118. _passArray.add(index+1);
  119. setState(() {});
  120. }
  121. }
  122. },
  123. child: Container(
  124. color: index==9||index==11?Color(0xFFD0D5DC):Colors.white,
  125. child: Text(index==9?'删除':index==10?'0':index==11?'确认':'${index+1}',style: TextStyle(fontSize: zsp(40),color: Colors.black,fontWeight: FontWeight.bold),),
  126. alignment: Alignment.center,
  127. ),
  128. );
  129. },
  130. itemCount: 12,
  131. padding: EdgeInsets.all(0),
  132. physics: NeverScrollableScrollPhysics(),
  133. )
  134. )
  135. ],
  136. );
  137. }
  138. );
  139. }