Explorar o código

添加地址 选择器

lailin %!s(int64=4) %!d(string=hai) anos
pai
achega
c2849d385f
Modificáronse 1 ficheiros con 163 adicións e 58 borrados
  1. 163 58
      taskservice/lib/src/crtacc/page_crtacc.dart

+ 163 - 58
taskservice/lib/src/crtacc/page_crtacc.dart

@@ -1,6 +1,9 @@
+import 'package:city_pickers/city_pickers.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
+import 'package:fluttertoast/fluttertoast.dart';
+import 'package:path/path.dart';
 import 'package:taskservice/Common/JXColors.dart';
 import 'package:taskservice/Model/JXMemberModel.dart';
 import 'package:taskservice/Model/JXServiceModel.dart';
@@ -20,6 +23,14 @@ class _CreateAccPageState extends State<CreateAccPage> {
   TextEditingController birthController = TextEditingController();
   TextEditingController addrConotroller = TextEditingController();
   TextEditingController remarkConotroller = TextEditingController();
+
+  /*详细地址*/
+  Result address;
+
+  /*显示样式*/
+  TextStyle titleStyle;
+  TextStyle contentStyle;
+
   @override
   void initState() {
     super.initState();
@@ -30,6 +41,12 @@ class _CreateAccPageState extends State<CreateAccPage> {
     birthController.addListener(onInfoChanged);
     addrConotroller.addListener(onInfoChanged);
     remarkConotroller.addListener(onInfoChanged);
+
+    address = Result(provinceName: '省份', cityName: '城市', areaName: '区域');
+
+    /*设置样式*/
+    titleStyle = TextStyle(fontSize: 18, fontWeight: FontWeight.bold);
+    contentStyle = TextStyle(fontSize: 18, color: JXColors.k1F2529);
   }
 
   void onInfoChanged() {
@@ -42,47 +59,64 @@ class _CreateAccPageState extends State<CreateAccPage> {
 
   @override
   Widget build(BuildContext context) {
-    return MyScaffold(title: '新建会员', body: Column(
-      children: <Widget>[
-        Expanded(
-          child: CustomScrollView(physics:BouncingScrollPhysics(),
-            slivers: <Widget>[
-              buildEditPart(),
-              buildItemsPart(),
-              SliverToBoxAdapter(
-                child: Container(
-                  decoration: BoxDecoration(
-                      borderRadius: BorderRadius.circular(12),
-                      border: Border.all(
-                        width: 1,
-                      )),
-                  margin: EdgeInsets.symmetric(vertical: 12, horizontal: 80),
-                  child: InkWell(
-                    onTap: () {
-                      /*跳转到服务*/
-                      Navigator.of(context).pushNamed('$CreateServiceList',
-                          arguments: {'services': member.services}).then((value) {
+    return MyScaffold(
+        title: '新建会员',
+        body: Column(
+          children: <Widget>[
+            Expanded(
+              child: CustomScrollView(
+                physics: BouncingScrollPhysics(),
+                slivers: <Widget>[
+                  buildEditPart(),
+                  buildItemsPart(),
+                  SliverToBoxAdapter(
+                    child: Container(
+                      decoration: BoxDecoration(
+                          borderRadius: BorderRadius.circular(12),
+                          border: Border.all(
+                            width: 1,
+                          )),
+                      margin:
+                          EdgeInsets.symmetric(vertical: 12, horizontal: 80),
+                      child: InkWell(
+                        onTap: () {
+                          /*跳转到服务*/
+                          Navigator.of(context).pushNamed('$CreateServiceList',
+                              arguments: {
+                                'services': member.services
+                              }).then((value) {
                             print(value.toString());
                             onClickAddServer(value);
-                      });
-                    },
-                    child: Container(
-                      padding: EdgeInsets.all(8),
-                      child: Text(
-                        '添加服务',
-                        textAlign: TextAlign.center,
-                        style: TextStyle(fontSize: 18),
+                          });
+                        },
+                        child: Container(
+                          padding: EdgeInsets.all(8),
+                          child: Text(
+                            '添加服务',
+                            textAlign: TextAlign.center,
+                            style: TextStyle(fontSize: 18),
+                          ),
+                        ),
                       ),
                     ),
                   ),
-                ),
+                ],
               ),
-            ],
-          ),
-        ),
-        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),)),
-      ],
-    ));
+            ),
+            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),
+                )),
+          ],
+        ));
   }
 
   SliverList buildItemsPart() {
@@ -140,12 +174,15 @@ class _CreateAccPageState extends State<CreateAccPage> {
             ),
             Text(
               '姓名',
-              style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
+              style: titleStyle,
             ),
             Expanded(
                 child: Padding(
               padding: const EdgeInsets.symmetric(horizontal: 20),
-              child: TextField(controller: nameController,),
+              child: TextField(
+                style: contentStyle,
+                controller: nameController,
+              ),
             )),
           ],
         ),
@@ -157,12 +194,15 @@ class _CreateAccPageState extends State<CreateAccPage> {
             ),
             Text(
               '电话',
-              style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
+              style: titleStyle,
             ),
             Expanded(
                 child: Padding(
               padding: const EdgeInsets.symmetric(horizontal: 20),
-              child: TextField(controller: phoneController,),
+              child: TextField(
+                style: contentStyle,
+                controller: phoneController,
+              ),
             )),
           ],
         ),
@@ -174,12 +214,15 @@ class _CreateAccPageState extends State<CreateAccPage> {
             ),
             Text(
               '生日',
-              style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
+              style: titleStyle,
             ),
             Expanded(
                 child: Padding(
               padding: const EdgeInsets.symmetric(horizontal: 20),
-              child: TextField(controller: birthController,),
+              child: TextField(
+                style: contentStyle,
+                controller: birthController,
+              ),
             )),
           ],
         ),
@@ -193,16 +236,35 @@ class _CreateAccPageState extends State<CreateAccPage> {
               ),
               Text(
                 '地址',
-                style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
+                style: titleStyle,
               ),
               Expanded(
-                child: Padding(
-                  padding: const EdgeInsets.symmetric(horizontal: 20),
-                  child: Container(
-                      margin: EdgeInsets.only(bottom: 1),
-                      child: Text(),
+                  child: Padding(
+                padding: const EdgeInsets.symmetric(horizontal: 20),
+                child: Container(
+                  margin: EdgeInsets.only(bottom: 1),
+                  child: Listener(
+                    onPointerDown: (e) {
+                      /*点击弹出地址选择框*/
+                      onClickAddressPicker();
+                      //Result result = await CityPickers.showCityPicker(context: context);
+                    },
+                    child: Row(
+                      children: [
+                        Text('${address.provinceName}', style: contentStyle,),
+                        SizedBox(
+                          width: 6,
+                        ),
+                        Text('${address.cityName}', style: contentStyle),
+                        SizedBox(
+                          width: 6,
+                        ),
+                        Text('${address.areaName}', style: contentStyle),
+                      ],
+                    ),
+                  ),
                 ),
-              ),
+              )),
             ],
           ),
         ),
@@ -224,18 +286,22 @@ class _CreateAccPageState extends State<CreateAccPage> {
               alignment: Alignment.center,
               child: Text(
                 '详细地址',
-                style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
+                style: titleStyle,
               ),
             ),
             Expanded(
-                child: Padding(
+              child: Padding(
               padding: const EdgeInsets.symmetric(horizontal: 20),
               child: Container(
                   decoration: BoxDecoration(
                       border: Border.all(color: JXColors.kE6E6E6, width: 2),
                       borderRadius: BorderRadius.circular(12)),
-                  height: 150,
-                  child: TextField(decoration: null, controller: addrConotroller,)),
+                  height: 90,
+                  child: TextField(
+                    style: contentStyle,
+                    decoration: null,
+                    controller: addrConotroller,
+                  )),
             )),
           ],
         ),
@@ -254,7 +320,7 @@ class _CreateAccPageState extends State<CreateAccPage> {
               alignment: Alignment.center,
               child: Text(
                 '备注',
-                style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
+                style: titleStyle,
               ),
             ),
             Expanded(
@@ -265,7 +331,11 @@ class _CreateAccPageState extends State<CreateAccPage> {
                       border: Border.all(color: JXColors.kE6E6E6, width: 2),
                       borderRadius: BorderRadius.circular(12)),
                   height: 150,
-                  child: TextField(decoration: null, controller: remarkConotroller,)),
+                  child: TextField(
+                    style: contentStyle,
+                    decoration: null,
+                    controller: remarkConotroller,
+                  )),
             )),
           ],
         ),
@@ -277,7 +347,7 @@ class _CreateAccPageState extends State<CreateAccPage> {
           decoration: BoxDecoration(color: JXColors.kE6E6E6),
           child: Text(
             '服务',
-            style: TextStyle(color: JXColors.k2E3032),
+            style: TextStyle(fontSize: 16, color: JXColors.k2E3032),
           ),
         ),
       ]),
@@ -286,15 +356,50 @@ class _CreateAccPageState extends State<CreateAccPage> {
 
   /*保存*/
   Future<void> onClickSave() async {
-    (await MyDataBase.database).saveMember(member);
-    Navigator.of(context).pop();
+    /*获取地址参数*/
+    if (address.areaId.length > 0) {
+      member.prov = address.provinceName;
+      member.city = address.cityName;
+      member.area = address.areaName;
+    }
+
+    /*检查参数*/
+    String errMsg;
+    if (member.name.length == 0) {
+      errMsg = '请输入姓名';
+    } else if (member.tel.length == 0) {
+      errMsg = '请输入电话';
+    } else if (member.birth.length == 0) {
+      errMsg = '请选择生日';
+    } else if (member.prov.length == 0) {
+      errMsg = '请选择地址';
+    } else if (member.addr.length == 0) {
+      errMsg = '请输入详细地址';
+    }
+
+    if (errMsg.length > 0) {
+      Fluttertoast.showToast(
+        msg: errMsg,
+        gravity: ToastGravity.CENTER,
+      );
+    } else {
+      (await MyDataBase.database).saveMember(member);
+      Navigator.of(this.context).pop();
+    }
   }
 
   /*界面返回后添加服务*/
-  void onClickAddServer(List <JXServiceModel> services) {
+  void onClickAddServer(List<JXServiceModel> services) {
     print('添加多个服务');
     member.services.clear();
     member.services.addAll(services);
     setState(() {});
   }
+
+  /*弹出地址选择框*/
+  Future<void> onClickAddressPicker() async {
+    Result result = await CityPickers.showCityPicker(context: this.context);
+    address = result;
+    setState(() {});
+  }
 }