当键盘显示时颤振形状消失
问题描述:
我用Flutter创建了一个Form
,但是当我专注于一个场并弹出键盘时,内容消失。当键盘显示时颤振形状消失
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:greencat/greencat.dart';
import 'package:woody_app/Application.dart';
import 'package:woody_app/actions/AuthAction.dart';
import 'package:woody_app/states/AuthState.dart';
class ProfileScreen extends StatefulWidget {
@override
State createState() => new ProfileScreenState();
}
class PersonData {
String name = '';
String phoneNumber = '';
String password = '';
}
class ProfileScreenState extends State<ProfileScreen> {
final Store<AuthState, AuthAction<dynamic>> _store = Application.get().store;
StreamSubscription<AuthState> _subscriber;
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
PersonData person = new PersonData();
void showInSnackBar(String value) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text(value)
));
}
bool _autovalidate = false;
final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
void _handleSubmitted() {
final FormState form = _formKey.currentState;
if (!form.validate()) {
_autovalidate = true; // Start validating on every change.
showInSnackBar('Please fix the errors in red before submitting.');
} else {
form.save();
showInSnackBar('${person.name}\'s phone number is ${person.phoneNumber}');
}
}
String _validateName(String value) {
if (value.isEmpty)
return 'Name is required.';
final RegExp nameExp = new RegExp(r'^[A-za-z ]+$');
if (!nameExp.hasMatch(value))
return 'Please enter only alphabetical characters.';
return null;
}
@override
void initState() {
super.initState();
_subscriber = _store.stream.listen((AuthState state) {
setState(() {});
});
}
@override
void dispose() {
_subscriber.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Container(child: new Form(
key: _formKey,
autovalidate: _autovalidate,
child: new ListView(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
children: <Widget>[
new TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.person),
hintText: 'What do people call you?',
labelText: 'Name *',
),
onSaved: (String value) {
person.name = value;
},
validator: _validateName,
),
new Container(
padding: const EdgeInsets.all(20.0),
alignment: const FractionalOffset(0.5, 0.5),
child: new FlatButton(
child: const Text('SUBMIT'),
onPressed: _handleSubmitted,
),
),
new Container(
padding: const EdgeInsets.only(top: 20.0),
child: new Text('* indicates required field', style: Theme
.of(context)
.textTheme
.caption),
),
],
)
));
}
}
是的,但我不能得到解决方法工作.. –
尝试更长的延迟 –
所以我必须等待一点时间来解决? –