我有一个列表视图,它有一个卡片作为列表视图的一个子节点。该卡片包含一个带有表单键的TextFormField。由于它是一个列表视图,它用相同的表单键多次建立卡片,所以出现了错误。
Duplicate GlobalKey detected in widget tree.
请帮助我解决这个问题。
This is my code.
final GlobalKey<FormState> _formKey =
new GlobalKey<FormState>(debugLabel: ' _formKey');
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.symmetric(
horizontal: 15,
vertical: 4,
child: Padding(
padding: EdgeInsets.all(8),
child: Column(
children: <Widget>[
ListTile(
leading: CircleAvatar(
backgroundColor: Colors.blue,
child: Padding(
padding: EdgeInsets.all(5),
child: FittedBox(
child: Text(
widget.price,
style: TextStyle(color: Colors.white),
title: Text('Title'),
subtitle: Text('Subtitle'),
trailing: Text(widget.quantity.toString() + ' x'),
Padding(
padding: const EdgeInsets.only(
left: 32, right: 5, top: 0, bottom: 5),
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Form(
key: this._formKey,
child: new TextFormField(
decoration: new InputDecoration(
hintText: 'Add your comments',
labelText: 'Comments'),
// validator: this._validateEmail,
onSaved: (String value) {
// _formKey.currentState.save();