flutter - 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;
},
),
],
);
}
}
解决方案
推荐阅读
- c# - 如何访问列表
类从接口继承时的对象属性? - python - 迭代生成键并计算字数
- python - 如何在 /apps for Python 中设置 pandas 库的路径,安装在 /opt 在 linux redhat 中
- api - 我对为什么我的 DOM 没有显示来自 storyblok 的 API 调用结果没有足够的了解
- apache-spark - Pyspark - 过滤数据框并创建排名列
- jquery - Webdriver-io:使用“=”查询元素文本会在浏览器控制台中出现错误
- java - 空手道如何模拟外部集成 URLS
- c# - 来自维基百科的解析表
- ios - Xcode - 归档项目时在框架模块中包含非模块化标头错误
- hibernate - 处理来自 JpaRepository 的附加列