Kaynağa Gözat

添加服务 编辑界面

lailin 4 yıl önce
ebeveyn
işleme
2b63582ad0

+ 54 - 0
taskservice/lib/Common/JXCommon.dart

@@ -0,0 +1,54 @@
+import 'package:flutter/services.dart';
+
+/*
+工具类
+* */
+// 限制小数位数
+class NumberTextInputFormatter extends TextInputFormatter {
+  static const defaultDouble = 0.001;
+
+  ///允许的小数位数,-1代表不限制位数
+  int digit;
+  NumberTextInputFormatter({this.digit = -1});
+
+  static double strToFloat(String str, [double defaultValue = defaultDouble]) {
+    try {
+      return double.parse(str);
+    } catch (e) {
+      return defaultValue;
+    }
+  }
+
+  ///获取目前的小数位数
+  static int getValueDigit(String value) {
+    if (value.contains(".")) {
+      return value.split(".")[1].length;
+    } else {
+      return -1;
+    }
+  }
+
+  @override
+  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
+    // TODO: implement formatEditUpdate
+    String value = newValue.text;
+    int selectionIndex = newValue.selection.end;
+    if (value == ".") {
+      value = "0.";
+      selectionIndex++;
+    } else if(value=="-"){
+      value = "-";
+      selectionIndex++;
+    }else if (value != "" &&
+        value != defaultDouble.toString() &&
+        strToFloat(value, defaultDouble) == defaultDouble ||
+        getValueDigit(value) > digit) {
+      value = oldValue.text;
+      selectionIndex = oldValue.selection.end;
+    }
+    return new TextEditingValue(
+      text: value,
+      selection: new TextSelection.collapsed(offset: selectionIndex),
+    );
+  }
+}

+ 3 - 0
taskservice/lib/main.dart

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
 import 'package:taskservice/src/acclist/page_acclist.dart';
 import 'package:taskservice/src/crtacc/page_crtacc.dart';
 import 'package:taskservice/src/home/home.dart';
+import 'package:taskservice/src/service/page_addservice.dart';
 import 'package:taskservice/src/service/page_servicelist.dart';
 
 void main() {
@@ -22,6 +23,8 @@ class MyApp extends StatelessWidget {
           return CupertinoPageRoute(builder: (context)=> AccountListPage());
         }else if(name == '$CreateServiceList') {
           return CupertinoPageRoute(builder: (context)=> CreateServiceList());
+        }else if(name == '$CreateAddService') {
+          return CupertinoPageRoute(builder: (context)=> CreateAddService());
         }
         return null;
       },

+ 1 - 1
taskservice/lib/src/home/home.dart

@@ -74,7 +74,7 @@ class _MyHomePageState extends State<MyHomePage> {
 
       },
       child: MyScaffold(
-        title: '吉祥之舍',
+        title: widget.title,
         body: Column(
           mainAxisAlignment: MainAxisAlignment.start,
           children: <Widget>[

+ 133 - 10
taskservice/lib/src/service/page_addservice.dart

@@ -1,27 +1,48 @@
-
-import 'dart:html';
-
 import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:taskservice/Common/JXColors.dart';
+import 'package:taskservice/Common/JXCommon.dart';
 import 'package:taskservice/Model/JXServiceModel.dart';
 import 'package:taskservice/src/custom_widgets.dart';
 
 class CreateAddService extends StatefulWidget {
   @override
   _CreateAddService createState() => _CreateAddService();
+
+  /*服务*/
+  final JXServiceModel service;
+  CreateAddService({Key key, this.service}) : super(key: key);
 }
 
 class _CreateAddService extends State<CreateAddService> {
   /*服务*/
   JXServiceModel _service;
   /*类型*/
-  TextEditingController kindController = TextEditingController();
+  TextEditingController kindController;
+  /*周期*/
+  TextEditingController cycleController;
+  /*提醒*/
+  TextEditingController remandController;
+  /*备注*/
+  TextEditingController remarkConotroller;
 
   @override
   void initState() {
     // TODO: implement initState
     super.initState();
-    _service = JXServiceModel();
+    if (widget.service == null) {
+      print('新建服务');
+      _service = JXServiceModel();
+    } else {
+      print('编辑服务');
+      _service = widget.service;
+      /*设置值*/
+      kindController = TextEditingController(text: _service.kind);
+      cycleController = TextEditingController(text: _service.cycle.toString());
+      remandController = TextEditingController(text: '0');
+      remarkConotroller = TextEditingController(text: _service.remark);
+    }
   }
 
   @override
@@ -50,13 +71,19 @@ class _CreateAddService extends State<CreateAddService> {
                   Container(
                     padding: EdgeInsets.all(0),
                     width: MediaQuery.of(context).size.width,
-                    height: 46.0,
+                    height: 52.0,
                     child: Row(
                       children: <Widget>[
-
+                        Expanded(
+                          child: SizedBox(width: 0,),
+                        ),
+                        theInputDayView('周期', '个月', cycleController),
+                        theInputDayView('提醒', '日', remandController),
                       ],
                     ),
                   ),
+                  SizedBox(height: 12.0,),
+                  theRemarkView(remarkConotroller),
                 ],
               ),
             ),
@@ -81,10 +108,106 @@ class _CreateAddService extends State<CreateAddService> {
         ),);
   }
 
+  /*天数输入框,限制2数字输入*/
+  Widget theInputDayView(String mark, String unit, TextEditingController controller) {
+    /*文字style*/
+    TextStyle style =  TextStyle(fontSize: 16.0, color: JXColors.k1F2529,);
+    return Container(
+      height: 52.0,
+      padding: EdgeInsets.only(left: 12.0, top: 12.0, right: 12.0),
+      child: Container(
+        padding: EdgeInsets.only(left: 12.0, right: 12.0),
+        decoration: BoxDecoration(
+          color: JXColors.kFFFFFF,
+          borderRadius: BorderRadius.circular(12.0),
+          border: Border.all(color: JXColors.kE6E6E6, width: 1),
+        ),
+        child: Row(
+          children: <Widget>[
+            Text(
+              mark,
+              style: style,
+            ),
+            SizedBox(width: 6.0,),
+            Container(
+              width: 24.0,
+              height: 46.0,
+              child: Center(
+                child: TextField(
+                  expands: false,
+                  textAlignVertical: TextAlignVertical.center,
+                  textAlign: TextAlign.center,
+                  decoration: InputDecoration.collapsed(hintText: '0',),
+                  style: style,
+                  keyboardType: TextInputType.numberWithOptions(signed: true,decimal: false),
+                  inputFormatters: [
+                    LengthLimitingTextInputFormatter(2),
+                    WhitelistingTextInputFormatter.digitsOnly,
+                  ],
+                  controller: controller,
+                ),
+              ),
+            ),
+            SizedBox(width: 6.0,),
+            Text(
+              unit,
+              style: style,
+            )
+          ],
+        ),
+      ),
+    );
+  }
+
+  /*备注输入框*/
+  Widget theRemarkView(TextEditingController controller) {
+    TextStyle style =  TextStyle(fontSize: 16.0, color: JXColors.k1F2529,);
+    return Row(
+      crossAxisAlignment: CrossAxisAlignment.start,
+      children: <Widget>[
+        SizedBox(width: 24.0,),
+        Container(
+          margin: EdgeInsets.only(top: 8),
+          alignment: Alignment.center,
+          child: Text(
+            '备注',
+            style: style,
+          ),
+        ),
+        Expanded(
+            child: Padding(
+              padding: const EdgeInsets.symmetric(horizontal: 20),
+              child: Container(
+                  decoration: BoxDecoration(
+                      border: Border.all(color: JXColors.kE6E6E6, width: 1),
+                      borderRadius: BorderRadius.circular(12)),
+                  height: 88,
+                  child: Container(
+                    padding: EdgeInsets.all(6.0),
+                    child: TextField(
+                      minLines: 1,
+                      maxLines: 4,
+                      decoration: null,
+                      style: style,
+                      textInputAction: TextInputAction.done,
+                      controller: controller,
+                    ),
+                  )
+              ),
+            )),
+      ],
+    );
+  }
+
+
+  /**点击事件**/
   /*保存*/
   void saveBtnClickAction() {
-    print('保存');
+    _service.kind = kindController.text;
+    _service.cycle = int.parse(cycleController.text);
+    _service.remindDay = int.parse(remandController.text);
+    _service.remark = remarkConotroller.text;
+    _service.cycleUnit = '月';
+    print(_service.toMap());
   }
-
-  /*输入框*/
 }

+ 5 - 9
taskservice/lib/src/service/page_servicelist.dart

@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:taskservice/Common/JXColors.dart';
 import 'package:taskservice/Model/JXServiceModel.dart';
+import 'package:taskservice/src/service/page_addservice.dart';
 import '../custom_widgets.dart';
 
 class CreateServiceList extends StatefulWidget {
@@ -130,7 +131,7 @@ class _CreateServiceList extends State<CreateServiceList> {
         alignment: Alignment.topCenter,
         child: Column(
           children: <Widget>[
-            SizedBox(height: 8,),
+            SizedBox(height: 12,),
             Row(
               mainAxisAlignment: MainAxisAlignment.spaceBetween,
               children: <Widget>[
@@ -138,13 +139,13 @@ class _CreateServiceList extends State<CreateServiceList> {
                 Text('周期: ${service.cycle}${service.cycleUnit}'),
               ],
             ),
-            SizedBox(height: 20,),
+            SizedBox(height: 12,),
             Row(
               children: <Widget>[
                 Text('备注 ${service.remark}'),
               ],
             ),
-            SizedBox(height: 8,),
+            SizedBox(height: 12,),
             Divider(
               height: 2,
               thickness: 2,
@@ -184,11 +185,6 @@ class _CreateServiceList extends State<CreateServiceList> {
   /*添加信息的服务*/
   void addBtnClickAction() {
     print('添加服务');
-    _baseServices.add(JXServiceModel()
-      ..kind = ''
-      ..cycle = 2
-      ..cycleUnit = '日'
-      ..remark = '测试');
-    filterSevice();
+    Navigator.of(this.context).pushNamed('$CreateAddService');
   }
 }