首页 > 解决方案 > Flutter Stepper 不工作,Datepicker 不显示,密码眼不工作

问题描述

在这里,我输入了我的代码。我面临三个问题,验证完成后步进器不移动到下一步密码显示隐藏所有问题

**在这里我输入了我的代码。我面临三个问题,验证完成后步进器不移动到下一步密码显示隐藏所有问题

在这里,我输入了我的代码。我面临三个问题,验证完成后步进器不移动到下一步密码显示隐藏所有问题

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:email_validator/email_validator.dart';

import '../../globals.dart';

// Create a Form widget.
class MyCustomForm extends StatefulWidget {
  const MyCustomForm({Key? key}) : super(key: key);

  @override
  MyCustomFormState createState() {
    return MyCustomFormState();
  }
}

// Create a corresponding State class.
// This class holds data related to the form.
class MyCustomFormState extends State<MyCustomForm> {
  final _pformKey = GlobalKey<FormState>();
  final _aformKey = GlobalKey<FormState>();
  final _fformKey = GlobalKey<FormState>();

  static TextEditingController full_nameController = new TextEditingController();
  static TextEditingController emailController = new TextEditingController();
  static TextEditingController mobileController = new TextEditingController();
  static TextEditingController genderController = new TextEditingController();
  static TextEditingController dobController = new TextEditingController();
  static TextEditingController passwordController = new TextEditingController();
  static TextEditingController re_passwordController = new TextEditingController();
  static TextEditingController address1Controller = new TextEditingController();
  static TextEditingController address2Controller = new TextEditingController();
  static TextEditingController cityController = new TextEditingController();
  static TextEditingController pincodeController = new TextEditingController();
  @override
  Widget build(BuildContext context) {
    var currentStep = 0;

    List<Step> steps = [
      new Step(
        title: Text('Personal'),
        content: _personal(context,_pformKey),
        state: currentStep == 0 ? StepState.editing : StepState.indexed,
        isActive: true,
      ),
      new Step(
        title: Text('Account'),
        content: _account(context,_aformKey),
        state: currentStep == 0 ? StepState.editing : StepState.indexed,
        isActive: false,
      ),
    ];

    return  Scaffold(
      appBar: AppBar(
        backgroundColor: Global.mediumYellow,
        automaticallyImplyLeading: false,
        title: Text('Registeration Form'),
        centerTitle: false,
        leading: GestureDetector(
          onTap: () {
            Navigator.pop(context);
          },
          child: Icon(
            Icons.arrow_back,
            size: 30,
            color: Colors.white,
          ),
        ),
      ),
      body: Form(
        key: _pformKey,
        child: Stepper(
          currentStep: currentStep,
          steps: steps,
          type: StepperType.vertical,
          onStepTapped: (step) {
            setState(() {
              currentStep = step;
            });
          },
          onStepContinue: () {
            print (currentStep);
            if (currentStep==0) {
              if (_pformKey.currentState!.validate()) {
                setState(() => currentStep =1);
              }
            }
            print (currentStep);
          },
          onStepCancel: () {
            setState(() {
              if (currentStep > 0) {
                currentStep = currentStep - 1;
              } else {
                currentStep = 0;
              }
            });
          },
        ),
      ),
    );
  }

 **DateTime _date = DateTime(2020, 11, 17);
  void _selectDate(BuildContext cntxt) async {
    DateTime? newDate = await showDatePicker(
      context: cntxt,
      initialDate: _date,
      firstDate: DateTime(2017, 1),
      lastDate: DateTime(2022, 7),
      helpText: 'Select a date',
    );
    if (newDate != null) {
      setState(() {
        _date = newDate;
      });
    }
  }**


  _personal(BuildContext contxt,_fkey){
    return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          
          InkWell(
            onTap: ()  {
              _selectDate(contxt);
            },

            child: TextFormField(
              maxLines: 1,
              controller: dobController,
              keyboardType: TextInputType.datetime,
              decoration: InputDecoration(
                contentPadding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                prefixIcon: const Icon(
                  Icons.calendar_today_outlined,
                  color: Global.mediumYellow,
                ),

                labelText: "Date of birth",
                labelStyle: TextStyle(
                  fontSize: 16.0,
                  fontFamily: "Raleway Light",
                ),
                hintStyle: TextStyle(
                  color:Global.mediumYellow,
                  fontSize: 15.0,
                ),

                border: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(3)),
                ),
              ),
              validator: (value) {
                if (value == null || value.isEmpty) {
                  return 'Please enter mobile number';
                }
                return null;
              },
            ),
          ),
          SizedBox(height: 20),           
        ],
      );

  }

  _account(BuildContext contxt,_fkey){
    bool _showPassword = false;
    bool _showrePassword = false;
    return  Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(height: 20),
          TextFormField(
            maxLines: 1,
            controller: re_passwordController,
            obscureText: !_showrePassword,
            keyboardType: TextInputType.text,
            decoration: InputDecoration(
              contentPadding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
              prefixIcon: const Icon(
                Icons.security,
                color: Global.mediumYellow,
              ),
              suffix: InkWell(
                onTap:() {
                  setState(() {
                    _showrePassword = !_showrePassword;
                  });
                },
                child: Icon(
                  _showrePassword
                      ? Icons.visibility
                      : Icons.visibility_off,
                ),
              ),
              labelText: "Password",
              labelStyle: TextStyle(
                fontSize: 16.0,
                fontFamily: "Raleway Light",
              ),
              hintStyle: TextStyle(
                color:Global.mediumYellow,
                fontSize: 15.0,
              ),

              border: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(3)),
              ),
            ),
            validator: (value) {
              if (value == null || value.isEmpty) {
                return 'Please enter confirm password';
              }else if  (value.length<8) {
                return 'Password must be min 8 characters';
              }else if (value != passwordController.text) {
                return 'Password and confirm password are not same.';
              }
              return null;
            },
          ),
        ],
      );
  }


} 

标签: flutterdatepickerstepper

解决方案


推荐阅读