Flutter 如何在颤振中清除按钮点击上清除整个窗体

Flutter 如何在颤振中清除按钮点击上清除整个窗体,flutter,checkbox,flutter-layout,reset,Flutter,Checkbox,Flutter Layout,Reset,如何在用户单击“清除”按钮时清除整个表单。我已经试过了,但是当我按下清除按钮时,它不会清除条款和条件复选框和下拉列表 所以我希望当用户按下清除按钮时,它会清除整个表单 这是我试过的代码。希望你能理解这个问题。你的帮助将不胜感激 import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:image/mobile_register_scree.dart'; impor

如何在用户单击“清除”按钮时清除整个表单。我已经试过了,但是当我按下清除按钮时,它不会清除条款和条件复选框和下拉列表

所以我希望当用户按下清除按钮时,它会清除整个表单

这是我试过的代码。希望你能理解这个问题。你的帮助将不胜感激

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:image/mobile_register_scree.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:geocoder/geocoder.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:image/page2.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
import 'package:pin_entry_text_field/pin_entry_text_field.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

import 'package:shared_preferences/shared_preferences.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SignupScreen(),
    );
  }
}

class SignupScreen extends StatefulWidget {
  @override
  _SignupScreenState createState() => new _SignupScreenState();
}

class _SignupScreenState extends State<SignupScreen> {
  final formKey = new GlobalKey<FormState>();
  bool _validate = false;
  List<Country> _countries = [];
  bool _obscureText = true;
  Person person = new Person();

  String passcode;
  final _emailFocusNode = new FocusNode();
  final _passwordFocusNode = new FocusNode();
  final _fnameFocuNode = new FocusNode();
  final _lnameFocusNode = new FocusNode();

  final TextEditingController _email = new TextEditingController();
  final TextEditingController _add = new TextEditingController();
  final TextEditingController _fn = new TextEditingController();
  final TextEditingController _ln = new TextEditingController();
  final TextEditingController _pho = new TextEditingController();
  final TextEditingController _pass = new TextEditingController();
  TextEditingController phoneController = new TextEditingController();
  static List<CountryModel> _dropdownItems = new List();
  String otpWaitTimeLabel = "";
  CountryModel _dropdownValue;
  TextEditingController otpcontroller = TextEditingController();
  String thisText = "";
  int pinLength = 6;
  bool hasError = false;
  bool showAlertBox = false;
  String errorMessage;
  SharedPreferences prefs;
  DateTime target;
  bool hasTimerStopped = false;

  final changeNotifier = StreamController<Functions>.broadcast();
  ValueChanged _onChanged = (val) => print(val);

  bool _submit() {
    final form = formKey.currentState;
    if (form.validate()) {
      form.save();
      return true;
    } else {
      return false;
    }
  }

  Widget _buildEmailField() {
    return TextFormField(
      controller: _email,
      focusNode: _emailFocusNode,
      decoration: new InputDecoration(
        prefixIcon: Icon(
          Icons.email,
        ),
        labelText: "Email",
        border: UnderlineInputBorder(),
        filled: false,
        hintText: 'Your email address',
      ),
      keyboardType: TextInputType.emailAddress,
      onSaved: (String value) {
        print('person');
        print(person);
        person.email = value.trim();
      },
    );
  }

  Widget _buildCountry(List<Country> countries) {
    if (countries.length > 0 && _dropdownItems.length != countries.length - 1) {
      print("countries list");
      print(countries[0].name);
      for (int i = 0; i < countries.length; i++) {
        if (countries[i].name.toLowerCase() != 'world') {
          _dropdownItems.add(
            CountryModel(
                country: countries[i].name, countryCode: countries[i].isdCode),
          );
        }
      }
    }
    return FormBuilder(
      autovalidate: true,
      initialValue: {},
      child: FormBuilderCustomField(
        attribute: "Country",
        validators: [
          FormBuilderValidators.required(),
        ],
        formField: FormField(
          builder: (FormFieldState<dynamic> field) {
            return DropdownButtonHideUnderline(
              child: new Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  new InputDecorator(
                    decoration: InputDecoration(
                      filled: false,
                      hintText: 'Choose Country',
                      prefixIcon: Icon(Icons.location_on),
                      labelText: _dropdownValue == null
                          ? 'Where are you from'
                          : 'From',
                      errorText: field.errorText,
                    ),
                    isEmpty: _dropdownValue == null,
                    child: new DropdownButton<CountryModel>(
                      value: _dropdownValue,
                      isDense: true,
                      onChanged: (CountryModel newValue) {
                        print('value change');
                        print(newValue);
                        person.country = newValue.country;
                        person.countryCode = newValue.countryCode;
                        setState(() {
                          _dropdownValue = newValue;
                          phoneController.text = _dropdownValue.countryCode;
                          field.didChange(newValue);
                        });
                      },
                      items: _dropdownItems.map(
                        (CountryModel value) {
                          return DropdownMenuItem<CountryModel>(
                            value: value,
                            child: Text(value.country),
                          );
                        },
                      ).toList(),
                    ),
                  ),
                ],
              ),
            );
          },
        ),
      ),
    );
  }

  Widget _buildTermsAndContionsCheck() {
    return FormBuilderCheckbox(
      attribute: 'accept_terms',
      initialValue: false,
      onChanged: _onChanged,
      leadingInput: true,
      label: RichText(
        text: TextSpan(
          children: [
            TextSpan(
              text: 'I have read and agree to the ',
              style: TextStyle(color: Colors.black),
            ),
            TextSpan(
                text: 'Terms and Conditions',
                style: TextStyle(color: Colors.blue),
                recognizer: TapGestureRecognizer()
                  // ..onTap = () {
                  //   print("launch url");
                  // },
                  ..onTap = () => _launchURL()),
          ],
        ),
      ),
      validators: [
        FormBuilderValidators.requiredTrue(
          errorText: "You must accept terms and conditions to continue",
        ),
      ],
    );
  }

  Widget _buildSignupButton(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: <Widget>[
        new FlatButton.icon(
          icon: Icon(Icons.close),
          label: Text('Clear'),
          textColor: Colors.black,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(7),
          ),
          onPressed: () {
            _email.clear();
            _fn.clear();
            _ln.clear();
            _pho.clear();
            _add.clear();
            _pass.clear();
            mobilecontroller.clear();
          },
        ),
        new FlatButton.icon(
            icon: Icon(Icons.accessibility_new),
            label: Text('TUDO Sign Up'),
            color: Colors.amber,
            textColor: Colors.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(7),
            ),
            onPressed: () {
              if (formKey.currentState.validate()) {
                person.email = _email.text;
                person.phoneNumber = mobilecontroller.text;
                person.firstname = _fn.text;
                person.lastname = _ln.text;
                person.password = _pass.text;

                // _onAlertotp(signupVm);
                // } else {
                // print('Error: while sign up the user');
                // print(signupVm.error);
                // }
              }
            }),
        // _buildSignupButton(context, signupVm),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text("Signup"),
        // leading: Icon(Icons.arrow_back_ios),
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios),
          onPressed: () {},
        ),
        centerTitle: true,
      ),
      body: Container(
        height: double.infinity,
        width: double.infinity,
        child: SafeArea(
          top: false,
          bottom: false,
          child: Form(
            key: formKey,
            autovalidate: _validate,
            child: Stack(
              children: <Widget>[
                // Background(),
                SingleChildScrollView(
                  dragStartBehavior: DragStartBehavior.down,
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  child: new Container(
                    margin: EdgeInsets.fromLTRB(30, 0, 30, 10),
                    child: new Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        _buildEmailField(),
                        _buildCountry(countries),
                        _buildTermsAndContionsCheck(),
                        _buildSignupButton(context),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

const List<Color> signInGradients = [
  Color(0xFF0EDED2),
  Color(0xFF03A0FE),
];

const List<Color> signUpGradients = [
  Color(0xFFFF9945),
  Color(0xFFFc6076),
];

class Person {
  String email = '';
  String country = '';
  String countryCode = '';
  String phoneNumber = '';
  String firstname = '';
  String lastname = '';
  String password = '';
  bool termsAndCondition = false;
}

class CountryModel {
  String country = '';
  String countryCode = '';

  CountryModel({
    this.country,
    this.countryCode,
  });
}
import'package:flatter/signatures.dart';
进口“包装:颤振/材料.省道”;
导入“package:image/mobile_register_scree.dart”;
导入“dart:async”;
进口“包装:颤振/材料.省道”;
导入“包:geocoder/geocoder.dart”;
导入“包:google_-maps_-flatter/google_-maps_-flatter.dart”;
导入“package:image/page2.dart”;
导入“package:pin_code_fields/pin_code_fields.dart”;
导入“package:pin_entry_text_field/pin_entry_text_field.dart”;
导入“package:shared_preferences/shared_preferences.dart”;
导入“dart:async”;
导入“package:flatter/signatures.dart”;
进口“包装:颤振/材料.省道”;
导入“包:flifter/services.dart”;
导入“包:flatter_form_builder/flatter_form_builder.dart”;
导入“package:shared_preferences/shared_preferences.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主页:屏幕上方的签名(),
);
}
}
类SignupScreen扩展StatefulWidget{
@凌驾
_SignupScreenState createState()=>新建_SignupScreenState();
}
类_SignupScreenState扩展状态{
final formKey=new GlobalKey();
bool _validate=false;
列出_国家=[];
bool _obsolizeText=true;
Person=新人();
字符串密码;
最终的_emailFocusNode=新的FocusNode();
final _passwordFocusNode=新的FocusNode();
最终的_fnameFocuNode=新的FocusNode();
最终的_lnameFocusNode=新的FocusNode();
final TextEditingController _email=new TextEditingController();
最终文本编辑控制器_add=新文本编辑控制器();
最终文本编辑控制器_fn=新文本编辑控制器();
最终文本编辑控制器_ln=新文本编辑控制器();
最终文本编辑控制器_pho=新文本编辑控制器();
最终文本编辑控制器_pass=新文本编辑控制器();
TextEditingController电话控制器=新的TextEditingController();
静态列表_dropdownItems=新列表();
字符串otpWaitTimeLabel=“”;
CountryModel\u下拉列表值;
TextEditingController otpcontroller=TextEditingController();
字符串thisText=“”;
int pinLength=6;
bool hasrerror=false;
bool showAlertBox=false;
字符串错误消息;
共享引用优先权;
日期时间目标;
bool-hastinmerstopped=false;
final changeNotifier=StreamController.broadcast();
值更改_onChanged=(val)=>打印(val);
bool_submit(){
最终形式=formKey.currentState;
if(form.validate()){
form.save();
返回true;
}否则{
返回false;
}
}
小部件_buildEmailField(){
返回TextFormField(
控制员:_电子邮件,
focusNode:_emailFocusNode,
装饰:新的输入装饰(
前缀:图标(
Icons.email,
),
labelText:“电子邮件”,
边框:下划线InputBorder(),
填充:假,
hintText:'您的电子邮件地址',
),
键盘类型:TextInputType.emailAddress,
onSaved:(字符串值){
印刷品(“人”);
印刷品(人);
person.email=value.trim();
},
);
}
Widget\u buildCountry(列出国家){
如果(countries.length>0&&u dropdownItems.length!=countries.length-1){
打印(“国家名单”);
打印(国家[0]。名称);
对于(int i=0;i    On click on Clear button put all thing inside setstate() like below.  
    Widget _buildTermsAndContionsCheck(bool isSelected) {
        return FormBuilderCheckbox(
          attribute: 'accept_terms',
          initialValue: isSelected,

      }

      class _SignupScreenState extends State<SignupScreen> {
      bool isSelected=false;
      }
                     onPressed: () {
                          setState(() {
                          _email.clear();
                            _fn.clear();
                            _ln.clear();
                            _pho.clear();
                            _add.clear();
                            _pass.clear();
                             bool isSelected=false;
                            mobilecontroller.clear();        
                              });

                          }
 onPressed: () {
              _formKey.currentState.reset();
              _bspPhone.clear();
              _bspBusinessName.clear();
              _bspBusinessLicense.clear();
              _bspLicenseAuthority.clear();
              _bspEstYear.clear();
              _bspNumberOfEmployee.clear();
              _bspBusinessDetailsComment.clear();
              _bspBusinessLegalAddress.clear();
            },