page_crtacc.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:taskservice/Common/JXColors.dart';
  5. import 'package:taskservice/Model/JXMemberModel.dart';
  6. import 'package:taskservice/Model/JXServiceModel.dart';
  7. import 'package:taskservice/database/DataBase.dart';
  8. import 'package:taskservice/src/custom_widgets.dart';
  9. class CreateAccPage extends StatefulWidget {
  10. @override
  11. _CreateAccPageState createState() => _CreateAccPageState();
  12. }
  13. class _CreateAccPageState extends State<CreateAccPage> {
  14. List<JXServiceModel> services;
  15. JXMemberModel member;
  16. TextEditingController nameController = TextEditingController();
  17. TextEditingController phoneController = TextEditingController();
  18. TextEditingController birthController = TextEditingController();
  19. TextEditingController addrConotroller = TextEditingController();
  20. TextEditingController remarkConotroller = TextEditingController();
  21. @override
  22. void initState() {
  23. super.initState();
  24. services = [
  25. JXServiceModel()
  26. ..kind = '清洗'
  27. ..cycle = 3
  28. ..cycleUnit = '个月'
  29. ..remark = '备注1',
  30. JXServiceModel()
  31. ..kind = '清洗2'
  32. ..cycle = 1
  33. ..cycleUnit = '个月'
  34. ..remark = '备注11',
  35. JXServiceModel()
  36. ..kind = '清洗3'
  37. ..cycle = 2
  38. ..cycleUnit = '个月'
  39. ..remark = '备注1111',
  40. JXServiceModel()
  41. ..kind = '清洗4'
  42. ..cycle = 30
  43. ..cycleUnit = '个月'
  44. ..remark = '备注111111',
  45. JXServiceModel()
  46. ..kind = '清洗5'
  47. ..cycle = 12
  48. ..cycleUnit = '个月'
  49. ..remark = '备注111111',
  50. JXServiceModel()
  51. ..kind = '清洗6'
  52. ..cycle = 2
  53. ..cycleUnit = '个月'
  54. ..remark = '备注111111',
  55. ];
  56. member = JXMemberModel();
  57. nameController.addListener(onInfoChanged);
  58. phoneController.addListener(onInfoChanged);
  59. birthController.addListener(onInfoChanged);
  60. addrConotroller.addListener(onInfoChanged);
  61. remarkConotroller.addListener(onInfoChanged);
  62. }
  63. void onInfoChanged() {
  64. member.name = nameController.value.text;
  65. member.tel = phoneController.value.text;
  66. member.birth = birthController.value.text;
  67. member.addr = addrConotroller.value.text;
  68. member.remark = remarkConotroller.value.text;
  69. }
  70. @override
  71. Widget build(BuildContext context) {
  72. return MyScaffold(title: '新建会员', body: Column(
  73. children: <Widget>[
  74. Expanded(
  75. child: CustomScrollView(physics:BouncingScrollPhysics(),
  76. slivers: <Widget>[
  77. buildEditPart(),
  78. buildItemsPart(),
  79. SliverToBoxAdapter(
  80. child: Container(
  81. decoration: BoxDecoration(
  82. borderRadius: BorderRadius.circular(12),
  83. border: Border.all(
  84. width: 1,
  85. )),
  86. margin: EdgeInsets.symmetric(vertical: 12, horizontal: 80),
  87. child: InkWell(
  88. onTap: () => null,
  89. child: Container(
  90. padding: EdgeInsets.all(8),
  91. child: Text(
  92. '添加服务',
  93. textAlign: TextAlign.center,
  94. style: TextStyle(fontSize: 18),
  95. ),
  96. ),
  97. ),
  98. ),
  99. ),
  100. ],
  101. ),
  102. ),
  103. GestureDetector(onTap: onClickSave, child: Container(width: MediaQuery.of(context).size.width, child: Text('保存', textAlign: TextAlign.center, style: TextStyle(fontSize: 16, color: JXColors.kFFFFFF),), padding: EdgeInsets.symmetric(vertical: 16), decoration: BoxDecoration(color: JXColors.k101E40),)),
  104. ],
  105. ));
  106. }
  107. SliverList buildItemsPart() {
  108. return SliverList(
  109. delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
  110. if (index <= services.length - 1) {
  111. var service = services[index];
  112. return Container(
  113. padding: EdgeInsets.symmetric(horizontal: 16),
  114. child: Column(
  115. children: <Widget>[
  116. SizedBox(height: 8,),
  117. Row(
  118. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  119. children: <Widget>[
  120. Text('类型: ${service.kind}'),
  121. Text('周期: ${service.cycle}${service.cycleUnit}'),
  122. ],
  123. ),
  124. SizedBox(height: 20,),
  125. Row(
  126. children: <Widget>[
  127. Text('备注 ${service.remark}'),
  128. ],
  129. ),
  130. SizedBox(height: 8,),
  131. Divider(
  132. height: 2,
  133. thickness: 2,
  134. ),
  135. ],
  136. ),
  137. );
  138. } else {
  139. return null;
  140. }
  141. }));
  142. }
  143. SliverList buildEditPart() {
  144. return SliverList(
  145. delegate: SliverChildListDelegate([
  146. Row(
  147. mainAxisSize: MainAxisSize.max,
  148. children: <Widget>[
  149. SizedBox(
  150. width: 20,
  151. ),
  152. Text(
  153. '姓名',
  154. style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  155. ),
  156. Expanded(
  157. child: Padding(
  158. padding: const EdgeInsets.symmetric(horizontal: 20),
  159. child: TextField(controller: nameController,),
  160. )),
  161. ],
  162. ),
  163. Row(
  164. mainAxisSize: MainAxisSize.max,
  165. children: <Widget>[
  166. SizedBox(
  167. width: 20,
  168. ),
  169. Text(
  170. '电话',
  171. style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  172. ),
  173. Expanded(
  174. child: Padding(
  175. padding: const EdgeInsets.symmetric(horizontal: 20),
  176. child: TextField(controller: phoneController,),
  177. )),
  178. ],
  179. ),
  180. Row(
  181. mainAxisSize: MainAxisSize.max,
  182. children: <Widget>[
  183. SizedBox(
  184. width: 20,
  185. ),
  186. Text(
  187. '生日',
  188. style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  189. ),
  190. Expanded(
  191. child: Padding(
  192. padding: const EdgeInsets.symmetric(horizontal: 20),
  193. child: TextField(controller: birthController,),
  194. )),
  195. ],
  196. ),
  197. Container(
  198. height: 44,
  199. child: Row(
  200. mainAxisSize: MainAxisSize.max,
  201. children: <Widget>[
  202. SizedBox(
  203. width: 20,
  204. ),
  205. Text(
  206. '地址',
  207. style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  208. ),
  209. Expanded(
  210. child: Padding(
  211. padding: const EdgeInsets.symmetric(horizontal: 20),
  212. child: Container(
  213. margin: EdgeInsets.only(bottom: 1),
  214. child: Text('省份/城市/区域')),
  215. )),
  216. ],
  217. ),
  218. ),
  219. Divider(
  220. height: 1,
  221. ),
  222. SizedBox(
  223. height: 12,
  224. ),
  225. Row(
  226. crossAxisAlignment: CrossAxisAlignment.start,
  227. children: <Widget>[
  228. SizedBox(
  229. width: 12,
  230. ),
  231. Container(
  232. margin: EdgeInsets.only(top: 8),
  233. width: 60,
  234. alignment: Alignment.center,
  235. child: Text(
  236. '详细地址',
  237. style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  238. ),
  239. ),
  240. Expanded(
  241. child: Padding(
  242. padding: const EdgeInsets.symmetric(horizontal: 20),
  243. child: Container(
  244. decoration: BoxDecoration(
  245. border: Border.all(color: JXColors.kE6E6E6, width: 2),
  246. borderRadius: BorderRadius.circular(12)),
  247. height: 150,
  248. child: TextField(decoration: null, controller: addrConotroller,)),
  249. )),
  250. ],
  251. ),
  252. SizedBox(
  253. height: 12,
  254. ),
  255. Row(
  256. crossAxisAlignment: CrossAxisAlignment.start,
  257. children: <Widget>[
  258. SizedBox(
  259. width: 12,
  260. ),
  261. Container(
  262. margin: EdgeInsets.only(top: 8),
  263. width: 60,
  264. alignment: Alignment.center,
  265. child: Text(
  266. '备注',
  267. style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
  268. ),
  269. ),
  270. Expanded(
  271. child: Padding(
  272. padding: const EdgeInsets.symmetric(horizontal: 20),
  273. child: Container(
  274. decoration: BoxDecoration(
  275. border: Border.all(color: JXColors.kE6E6E6, width: 2),
  276. borderRadius: BorderRadius.circular(12)),
  277. height: 150,
  278. child: TextField(decoration: null, controller: remarkConotroller,)),
  279. )),
  280. ],
  281. ),
  282. SizedBox(
  283. height: 12,
  284. ),
  285. Container(
  286. padding: EdgeInsets.all(12),
  287. decoration: BoxDecoration(color: JXColors.kE6E6E6),
  288. child: Text(
  289. '服务',
  290. style: TextStyle(color: JXColors.k2E3032),
  291. ),
  292. ),
  293. ]),
  294. );
  295. }
  296. Future<void> onClickSave() async {
  297. (await MyDataBase.database).saveMember(member);
  298. Navigator.of(context).pop();
  299. }
  300. }