class AddDineinOrderForm extends StatefulWidget {
final MainModel model;
AddDineinOrderForm(this.model);
@override
State createState() => _AddDineinOrderFormState();
}
class _AddDineinOrderFormState extends State<AddDineinOrderForm> {
final _formKey = new GlobalKey<FormState>();
final Map<String, dynamic> _formData = {
'userName': null,
'mobileNumber': null,
'noOfPersons': null
};
_onSubmit(model){
if (_formKey.currentState == null || !_formKey.currentState.validate()) {
return;
}
_formKey.currentState.save();
model.addNewDineInOrder(_formData);
Navigator.pushNamed(context, '/add_items');
}
Widget _customerNameField(){
return Container(
margin: EdgeInsets.only(bottom: 5.0),
child: TextFormField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.person),
filled: true,
fillColor: Color.fromRGBO(255, 255, 255, 1.0),
labelText: 'Customer Name',
),
onSaved: (val){
_formData['userName'] = val ;
},
validator: (val){
if(val.isEmpty){
return 'Please enter customer name';
}
},
),
);
}
Widget _customerNumberField(){
return Container(
margin: EdgeInsets.only(bottom: 5.0),
child: TextFormField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.phone_android),
filled: true,
fillColor: Color.fromRGBO(255, 255, 255, 1.0),
labelText: 'Customer Mobile Number',
),
onSaved: (val){
_formData['mobileNumber'] = val ;
},
validator: (val){
if(val.isNotEmpty && val.length != 10){
return 'Please enter valid mobile number';
}
},
keyboardType: TextInputType.number
),
);
}
Widget _buildMemberCount(){
return Container(
margin: EdgeInsets.only(bottom: 5.0),
child: TextFormField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.person_add),
filled: true,
fillColor: Color.fromRGBO(255, 255, 255, 1.0),
labelText: 'Number of persons on Table',
),
onSaved: (val){
_formData['noOfPersons'] = int.parse(val) ;
},
validator: (val){
if(val.isEmpty){
return 'Please enter number persons';
}
},
keyboardType: TextInputType.number
),
);
}
Widget _buildAddOrder(context, model){
return Container(
child: RaisedButton(
onPressed: () {
_onSubmit(model);
},
child: Text('Add Items',
style: TextStyle(color: Colors.white),
),
),
);
}
Widget _buildOrderForm(model){
return Form(
key: _formKey,
child: ListView(
children: <Widget>[
_customerNameField(),
_customerNumberField(),
_buildMemberCount(),
_buildAddOrder(context, model)
],
),
);
}
@override
Widget build(BuildContext context){
return ScopedModelDescendant(
builder: (BuildContext context, Widget child, MainModel model) {
return Scaffold(
appBar: AppBar(
title: Text('Add User Info'),
),
body: Container(
padding: EdgeInsets.all(10.0),
child: _buildOrderForm(model),
),
);
},
);
}
}
以下是错误
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3549 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4131 pos 14: '_dependents.isEmpty': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 1744 pos 12: '_elements.contains(element)': is not true.
I/flutter (24195): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 2284 pos 16: '!_dirtyElements[index]._active || _dirtyElements[index]._debugIsInScope(context)': is not true.
答案 0 :(得分:-1)
尝试以下代码:
Expanded(
child:Container(
padding: EdgeInsets.all(10.0),
child: _buildOrderForm(model),
),
)