问题描述
如何在不使用任何其他包的情况下在显示表单的同一屏幕上显示表格中的表单数据?
当用户输入宽度和长度并且验证正常时,我希望数据显示在存在表单的同一页面上,并在添加矩形和重置按钮下的表格中显示数据。
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
// debugShowCheckedModeBanner: false,title: 'Lab 5',theme: ThemeData(
primarySwatch: Colors.blue,visualDensity: VisualDensity.adaptivePlatformDensity,),home: Scaffold(
appBar: AppBar(
title: Text("Rectangles"),backgroundColor: Colors.red,body: MyHomePage(),);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _scaffoldkey = GlobalKey<ScaffoldState>();
final _formKey = GlobalKey<FormState>();
String _height;
String _width;
String _length;
void _showdata(){
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
}else{
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('Invalid form values!!'),duration: Duration(seconds: 3),);
}
}
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,child: Padding(
padding: const EdgeInsets.all(16.0),child: Column(
crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
TextFormField(
keyboardType: TextInputType.numberWithOptions(),cursorColor: Colors.red,decoration: Inputdecoration(
hintText: 'Enter the Width',hintStyle: TextStyle(color: Colors.grey),labelText: 'Width',labelStyle: TextStyle(color: Colors.red),validator: (value) {
if (value.isEmpty || value.contains('0') || value.contains('-')) {
return 'Invalid Input';
}
return null;
},onSaved: (value) => _width = value,TextFormField(
keyboardType: TextInputType.numberWithOptions(),decoration: Inputdecoration(
hintText: 'Enter the Length',labelText: 'Length',onSaved: (value) => _length = value,Padding(
padding: const EdgeInsets.all(20.0),child: Row(
children: [
RaisedButton(
onpressed: _showdata,child: Text("Add Rectangle",style: TextStyle(color: Colors.white),color: Colors.red,SizedBox(width: 70),RaisedButton(
onpressed: (){},textColor: Colors.white,child: Text("Reset"),],);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)