Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 未在颤振中签入复选框_Flutter_Checkbox - Fatal编程技术网

Flutter 未在颤振中签入复选框

Flutter 未在颤振中签入复选框,flutter,checkbox,Flutter,Checkbox,我正在创建一个带有特定字段的注册表单 我的复选框不起作用。启用复选框后,按钮应启用单击 TextFormField验证不起作用。 a) FirstName和Lastname不应为空。-如果未输入数据,则应显示错误消息 b) 电子邮件和手机号码验证。 c) 应进行密码验证 我正在创建这个小部件,需要调用Main.dart 下面是代码 注册,飞镖 import 'dart:developer'; import 'dart:ui'; import 'package:flutter/gestures.d

我正在创建一个带有特定字段的注册表单

  • 我的复选框不起作用。启用复选框后,按钮应启用单击
  • TextFormField验证不起作用。 a) FirstName和Lastname不应为空。-如果未输入数据,则应显示错误消息 b) 电子邮件和手机号码验证。 c) 应进行密码验证
  • 我正在创建这个小部件,需要调用Main.dart

    下面是代码

    注册,飞镖

    import 'dart:developer';
    import 'dart:ui';
    import 'package:flutter/gestures.dart';
    import 'package:url_launcher/url_launcher.dart';
    import 'package:flutter/services.dart';
    import 'package:flutter/material.dart';
    import 'package:email_validator/email_validator.dart';
    
    class SignUp extends StatefulWidget {
      HomePage createState() => HomePage();
    }
    
    class HomePage extends State<SignUp> {
      String _firstname;
      String _lastname;
      String _username;
      String _email;
      String _mobileno;
      String _password;
    
    
      @override
      Widget build(BuildContext context) {
        var screenSize = MediaQuery.of(context).size;
        bool agree = false;
    
        void _doSomething() {
          // Do something
        }
    
        void _onChanged(bool value){
          setState(() {
            agree = value;
          });
        }
        return Container(
          width: screenSize.width,
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/img/bg_signup.png"),
              fit: BoxFit.cover,
            ),
          ),
    
    
          child: SingleChildScrollView(
            child: Form(
              child: Column(children: [
            Padding(
    
              padding: EdgeInsets.fromLTRB(30, 10, 30, 0),
              child: new TextFormField(
                keyboardType: TextInputType.text,
                decoration: new InputDecoration(
                  labelText: "First Name",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
              ),
            ),
    
            Padding(
              padding: EdgeInsets.fromLTRB(30, 25, 30, 0),
              child: new TextFormField(
                keyboardType: TextInputType.text,
                decoration: new InputDecoration(
                  labelText: "Last Name",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
              ),
            ),
    
            Padding(
              padding: EdgeInsets.fromLTRB(30, 25, 30, 0),
              child: new TextFormField(
                decoration: new InputDecoration(
                  labelText: "Username",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
              ),
            ),
    
            Padding(
              padding: EdgeInsets.fromLTRB(30, 25, 30, 0),
              child: new TextFormField(
                decoration: new InputDecoration(
                  labelText: "Email",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                validator: (value) => EmailValidator.validate(value) ? null : "Please enter a valid email",
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
              ),
            ),
    
            Padding(
              padding: EdgeInsets.fromLTRB(30, 25, 30, 0),
              child: new TextFormField(
                keyboardType: TextInputType.number,
                decoration: new InputDecoration(
                  labelText: "Mobile Number",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
                
              ),
            ),
    
            Padding(
              padding: EdgeInsets.fromLTRB(30, 25, 30, 0),
              child: new TextFormField(
                decoration: new InputDecoration(
                  labelText: "Password",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
              ),
            ),
    
            Padding(
              padding: EdgeInsets.fromLTRB(30, 25, 30, 0),
              child: new TextFormField(
                decoration: new InputDecoration(
                  labelText: "Confirm Password",
                  labelStyle: new TextStyle(
                    fontFamily: 'Poppins',
                    fontWeight: FontWeight.w300,
                  ),
                  fillColor: Colors.white,
                  border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(10.0),
                    borderSide: BorderSide(color: Colors.blue),
                  ),
                ),
                style: new TextStyle(
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.w300,
                ),
              ),
            ),
    
            Row(
              children: [
                Material(
                  child: Checkbox(
                    checkColor: Colors.red,
                    focusColor: Colors.black,
                    value: agree,
                    onChanged: (bool value) {
                   _onChanged(value);
                    },
                  ),
                ),
    
                new Center(
               child: new RichText(
                text : new TextSpan(
                  children: [
                    new TextSpan(
                      text: 'Accept the ',
                      style: new TextStyle(color: Colors.black),
                    ),
                    new TextSpan(
                      text: 'terms and conditions',
                      style: new TextStyle(color: Colors.blue, fontWeight : FontWeight.bold ),
                      recognizer: new TapGestureRecognizer()
                        ..onTap = () {
                        Container(
                        child: AlertDialog(
                          title: Text('Reset settings?'),
                          content: Text('This will reset your device to its default factory settings.'),
                        ),
                        );   }
                    ),
                  ],
                ),
                ),
                ),
              ],
            ),
    
            ElevatedButton(onPressed: agree ? _doSomething : null, child: Text('Continue'))
            
          ])),
          ),
        );
      }
    }
    
    导入“dart:developer”;
    导入“dart:ui”;
    导入“package:flatter/signatures.dart”;
    导入“package:url_launcher/url_launcher.dart”;
    导入“包:flifter/services.dart”;
    进口“包装:颤振/材料.省道”;
    导入“包:email_validator/email_validator.dart”;
    类注册扩展了StatefulWidget{
    主页createState()=>主页();
    }
    类主页扩展状态{
    字符串_firstname;
    字符串_lastname;
    字符串\u用户名;
    字符串\u电子邮件;
    字符串_mobileno;
    字符串\u密码;
    @凌驾
    小部件构建(构建上下文){
    var screenSize=MediaQuery.of(context).size;
    bool-agree=false;
    void _doSomething(){
    //做点什么
    }
    void _onChanged(布尔值){
    设置状态(){
    同意=价值;
    });
    }
    返回容器(
    宽度:screenSize.width,
    装饰:盒子装饰(
    图像:装饰图像(
    图片:AssetImage(“assets/img/bg_signup.png”),
    适合:BoxFit.cover,
    ),
    ),
    子:SingleChildScrollView(
    孩子:表格(
    子项:列(子项:[
    填充物(
    填充:从LTRB(30,10,30,0)开始的边缘设置,
    子项:新建TextFormField(
    键盘类型:TextInputType.text,
    装饰:新的输入装饰(
    labelText:“名字”,
    标签样式:新的文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    fillColor:Colors.white,
    边框:新大纲输入边框(
    边界半径:新边界半径。圆形(10.0),
    borderSide:borderSide(颜色:Colors.blue),
    ),
    ),
    样式:新文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    ),
    ),
    填充物(
    填充:从LTRB(30,25,30,0)开始的边缘设置,
    子项:新建TextFormField(
    键盘类型:TextInputType.text,
    装饰:新的输入装饰(
    labelText:“姓氏”,
    标签样式:新的文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    fillColor:Colors.white,
    边框:新大纲输入边框(
    边界半径:新边界半径。圆形(10.0),
    borderSide:borderSide(颜色:Colors.blue),
    ),
    ),
    样式:新文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    ),
    ),
    填充物(
    填充:从LTRB(30,25,30,0)开始的边缘设置,
    子项:新建TextFormField(
    装饰:新的输入装饰(
    labelText:“用户名”,
    标签样式:新的文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    fillColor:Colors.white,
    边框:新大纲输入边框(
    边界半径:新边界半径。圆形(10.0),
    borderSide:borderSide(颜色:Colors.blue),
    ),
    ),
    样式:新文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    ),
    ),
    填充物(
    填充:从LTRB(30,25,30,0)开始的边缘设置,
    子项:新建TextFormField(
    装饰:新的输入装饰(
    labelText:“电子邮件”,
    标签样式:新的文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    fillColor:Colors.white,
    边框:新大纲输入边框(
    边界半径:新边界半径。圆形(10.0),
    borderSide:borderSide(颜色:Colors.blue),
    ),
    ),
    validator:(值)=>EmailValidator.validate(值)?null:“请输入有效电子邮件”,
    样式:新文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    ),
    ),
    填充物(
    填充:从LTRB(30,25,30,0)开始的边缘设置,
    子项:新建TextFormField(
    键盘类型:TextInputType.number,
    装饰:新的输入装饰(
    labelText:“手机号码”,
    标签样式:新的文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    fillColor:Colors.white,
    边框:新大纲输入边框(
    边界半径:新边界半径。圆形(10.0),
    borderSide:borderSide(颜色:Colors.blue),
    ),
    ),
    样式:新文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    ),
    ),
    填充物(
    填充:从LTRB(30,25,30,0)开始的边缘设置,
    子项:新建TextFormField(
    装饰:新的输入装饰(
    labelText:“密码”,
    标签样式:新的文本样式(
    fontFamily:“罂粟花”,
    fontWeight:fontWeight.w300,
    ),
    fillColor:Colors.white,
    边框:新大纲输入边框(
    边界半径:新边界半径。圆形(10.0)
    
    class MyWidget extends StatefulWidget {
      @override
      _MyWidgetState createState() => _MyWidgetState();
    }
    
    class _MyWidgetState extends State<MyWidget> {
      final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
      bool agree = false;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Padding(
            padding: const EdgeInsets.all(10.0),
            child: Form(
              key: _formKey,
              child: Column(
                children: [
                  TextFormField(
                    decoration: new InputDecoration(labelText: "First Name"),
                    validator: (val) {
                      if (val.isEmpty) {
                        return "Must not be empty";
                      }
                    },
                  ),
                  SizedBox(height: 10),
                  Checkbox(
                      value: agree,
                      onChanged: (check) {
                        setState(() {
                          agree = check;
                        });
                      }),
                  SizedBox(height: 10),
                  ElevatedButton(
                      onPressed: agree
                          ? () {
                              if (_formKey.currentState.validate()) {
                                print("DO Something");
                              }
                            }
                          : null,
                      child: Text('Continue'))
                ],
              ),
            ),
          ),
        );
      }
    }