【发布时间】:2018-12-21 13:45:37
【问题描述】:
我正在尝试使用颤振构建应用程序前端,这是我第一次遇到这样的错误:无法编辑我的 textformfield 因为我将表单元素放在列表视图中!当键盘出现在字段中输入一些文本时,它会在一秒钟内消失!我需要一个即时的解决方案:(
import 'package:flutter/material.dart';
import'package:dubai274_app/mobile_verif.dart';
import 'EnsureVisible.dart';
class SignUp extends StatefulWidget{
static String tag = 'Sign_up-page';
SignUp_Page createState() => SignUp_Page();
}
class SignUp_Page extends State<SignUp>{
List<DropdownMenuItem<String>> _Dropdownmenuitems;
String _statusSel;
List<DropdownMenuItem<String>> _getDropdownmenuitem(){
List<DropdownMenuItem<String>> items=new List();
items.add(new DropdownMenuItem(value:'Emirates',child: new Text('United Arab Emirates')));
items.add(new DropdownMenuItem(value:'Tun',child: new Text('Tunisia')));
return items;
}
void changeddropdowselecteditem(String selecteditem){
setState(() {
_statusSel=selecteditem;
});
}
@override
void initState() {
// TODO: implement initState
//listViewController=new ScrollController().addListener(_scrollListener);
_Dropdownmenuitems=_getDropdownmenuitem();
_statusSel=_Dropdownmenuitems[0].value;
}
@override
Widget build(BuildContext context) {
final scaffoldKey = GlobalKey<ScaffoldState>();
final formKey = GlobalKey<FormState>();
final TextEditingController _controller = new TextEditingController();
final first_value=TextFormField(autofocus: false,
validator: (val) =>
val.length < 6 ? 'First name required' : null,
decoration: InputDecoration(
labelText: 'First Name',
hintText: 'First Name',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),);
final family_value=TextFormField(autofocus: false,
decoration: InputDecoration(
labelText: 'Last Name',
hintText: 'Last Name',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),);
final Nationality=new DropdownButton(items: _Dropdownmenuitems, value:_statusSel,onChanged: changeddropdowselecteditem);
final email_value=TextFormField(keyboardType: TextInputType.emailAddress,
autofocus: false,
decoration: InputDecoration(
labelText: 'Email',
hintText: 'Email',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),);
final password=Column(children: <Widget>[ TextFormField(autofocus: false,
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Password',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),)), Text('Min 8 characters with at least one special character')]);
void _performsignup() {
final snackbar = SnackBar(
content: Text('Email: $email, password: $password'),
);
scaffoldKey.currentState.showSnackBar(snackbar);
}
void _submit() {
final form = formKey.currentState;
if (form.validate()) {
form.save();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MobileVerif()),
);
_performsignup();
}
}
final forward_signedin=FloatingActionButton(tooltip: 'Go forward',
child: Icon(Icons.arrow_forward,color: Colors.white,size: 38.4,),
onPressed: (){_submit();},);
return MaterialApp(
title: 'Sign_Up_Page',
home: Scaffold(
appBar: AppBar(
elevation: 0.0,
backgroundColor: Colors.transparent,
title: const Text('Sign Up',style: TextStyle(color: Colors.blueAccent, fontSize: 25.0,fontWeight: FontWeight.bold),textAlign: TextAlign.center,),
centerTitle: true,
leading: IconButton(
tooltip: 'Previous choice',
icon: const Icon(Icons.arrow_back_ios),
onPressed: () { Navigator.pop(context);},
color: Colors.black,
iconSize: 20.0,
),
),
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/background.png"),
fit: BoxFit.cover,
),
),
child: new Form( key: formKey,
child: new Padding( padding: new EdgeInsets.all(40.0), child: ListView(
children: <Widget>[
first_value,
family_value,
Nationality,
email_value,
password,
new ListTile( title:forward_signedin,)],
)) )
),
),
);
}
}
【问题讨论】:
-
如果你不分享你迄今为止尝试过的东西,我们就无法知道问题所在
-
@Farah,你找到解决方案了吗?