Shop.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import 'package:flutter/material.dart';
  2. import '../styles/colors.dart';
  3. class Shop extends StatefulWidget {
  4. @override
  5. State<StatefulWidget> createState() {
  6. return _ShopState();
  7. }
  8. Shop({Key key}) : super(key: key);
  9. }
  10. class _ShopState extends State<Shop> {
  11. @override
  12. Widget build(BuildContext context) {
  13. return Scaffold(
  14. appBar: AppBar(
  15. title: Text('商城'),
  16. centerTitle: true,
  17. ),
  18. body: Container(
  19. padding: EdgeInsets.all(7.5),
  20. child: GridView.builder(
  21. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  22. crossAxisCount: 3,
  23. childAspectRatio: 105 / 120,
  24. ),
  25. itemCount: 9,
  26. itemBuilder: (context, index) {
  27. switch (index) {
  28. case 0:
  29. return shopItem(
  30. icon: 'images/icon_jifen_01.png',
  31. text: '+10%积分',
  32. money: 100,
  33. color: Color(0xFF3EF166),
  34. );
  35. case 1:
  36. return shopItem(
  37. icon: 'images/icon_jifen_02.png',
  38. text: '+20%积分',
  39. money: 300,
  40. color: Color(0xFFF2F2F2),
  41. );
  42. case 2:
  43. return shopItem(
  44. icon: 'images/icon_jifen_03.png',
  45. text: '+40%积分',
  46. money: 500,
  47. color: Colors.yellow,
  48. );
  49. case 3:
  50. return shopItem(
  51. icon: 'images/icon_jifen_01.png',
  52. text: '+10%积分',
  53. money: 100,
  54. color: Color(0xFF3EF166),
  55. );
  56. case 4:
  57. return shopItem(
  58. icon: 'images/icon_jifen_02.png',
  59. text: '+20%积分',
  60. money: 300,
  61. color: Color(0xFFF2F2F2),
  62. );
  63. case 5:
  64. return shopItem(
  65. icon: 'images/icon_jifen_03.png',
  66. text: '+40%积分',
  67. money: 500,
  68. color: Colors.yellow,
  69. );
  70. case 6:
  71. return shopItem(
  72. icon: 'images/icon_jifen_01.png',
  73. text: '+10%积分',
  74. money: 100,
  75. color: Color(0xFF3EF166),
  76. );
  77. case 7:
  78. return shopItem(
  79. icon: 'images/icon_jifen_02.png',
  80. text: '+20%积分',
  81. money: 300,
  82. color: Color(0xFFF2F2F2),
  83. );
  84. case 8:
  85. return shopItem(
  86. icon: 'images/icon_jifen_03.png',
  87. text: '+40%积分',
  88. money: 500,
  89. color: Colors.yellow,
  90. );
  91. }
  92. return shopItem(
  93. icon: 'images/icon_jifen_01.png',
  94. text: '+10%积分',
  95. money: 100,
  96. color: Color(0xFF3EF166),
  97. );
  98. },
  99. ),
  100. ),
  101. );
  102. }
  103. Widget shopItem(
  104. {@required String icon,
  105. @required String text,
  106. @required int money,
  107. @required Color color}) {
  108. return GestureDetector(
  109. child: Container(
  110. padding: EdgeInsets.all(7.5),
  111. height: 120,
  112. child: Container(
  113. color: Color(0xFF293354),
  114. child: Column(
  115. mainAxisAlignment: MainAxisAlignment.center,
  116. children: <Widget>[
  117. Image.asset(icon),
  118. Text(
  119. text,
  120. style: TextStyle(color: color, fontSize: 10),
  121. ),
  122. Container(
  123. margin: EdgeInsets.only(top: 16),
  124. child: Row(
  125. mainAxisAlignment: MainAxisAlignment.center,
  126. children: <Widget>[
  127. Image.asset('images/icon_money.png'),
  128. Container(
  129. margin: EdgeInsets.only(left: 2),
  130. child: Text(
  131. money.toString(),
  132. style: TextStyle(
  133. color: Colors.yellow,
  134. fontSize: 14,
  135. fontWeight: FontWeight.bold,
  136. ),
  137. ),
  138. ),
  139. ],
  140. ),
  141. )
  142. ],
  143. ),
  144. ),
  145. ),
  146. onTap: () {
  147. // showModalBottomSheet(
  148. // context: context,
  149. // builder: (context) {
  150. // return Theme(
  151. // data: Theme.of(context).copyWith(canvasColor: Colors.transparent),
  152. // child: ChooseCount(),
  153. // );
  154. // },
  155. // );
  156. },
  157. );
  158. }
  159. }
  160. class ChooseCount extends StatefulWidget {
  161. @override
  162. State<StatefulWidget> createState() {
  163. return ChooseCountState();
  164. }
  165. }
  166. class ChooseCountState extends State<ChooseCount> {
  167. @override
  168. Widget build(BuildContext context) {
  169. return Container(
  170. padding: EdgeInsets.fromLTRB(16, 0, 16, 10),
  171. height: 285,
  172. width: double.infinity,
  173. color: Colors.transparent,
  174. child: Column(
  175. children: <Widget>[
  176. Container(
  177. height: 212,
  178. child: Stack(
  179. children: <Widget>[
  180. Align(
  181. alignment: Alignment.topCenter,
  182. child: Container(
  183. height: 197,
  184. margin: EdgeInsets.only(top: 15),
  185. color: SUB_COLOR,
  186. ),
  187. ),
  188. Align(
  189. alignment: Alignment.topLeft,
  190. child: Container(
  191. height: 85,
  192. width: 85,
  193. margin: EdgeInsets.fromLTRB(15, 0, 0, 0),
  194. color: SUB_COLOR,
  195. ),
  196. )
  197. ],
  198. ),
  199. ),
  200. Container(
  201. margin: EdgeInsets.only(top: 15),
  202. child: MaterialButton(
  203. highlightElevation: 0,
  204. elevation: 0,
  205. color: PRIMARY_COLOR,
  206. height: 48,
  207. minWidth: double.infinity,
  208. child: Text(
  209. '确定购买',
  210. style: TextStyle(
  211. color: Colors.white,
  212. fontSize: 16,
  213. fontWeight: FontWeight.bold,
  214. ),
  215. ),
  216. onPressed: () {},
  217. ),
  218. )
  219. ],
  220. ),
  221. );
  222. }
  223. }