请帮助。.我正在尝试制作更新数据页面,但是此错误在此行中出现..
Firestore.instance.collection('reg').add({'name':controllerName})
代码如下:
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class EditList extends StatefulWidget {
@override
_EditListState createState() => _EditListState();
}
class _EditListState extends State<EditList> {
TextEditingController controllerName;
@override
void initState() {
controllerName = new TextEditingController();
super.initState();
}
var name;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Registration'),
backgroundColor: Colors.blue,
),
body: Container(
child: SingleChildScrollView(
padding: const EdgeInsets.all(30.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 20.0),
),
Text('GROUP'),
TextField(
controller: controllerName,
onChanged: (String str) {
setState(() {
name= str;
});
},
decoration: InputDecoration(
labelText: 'Name',
)),
//paste here
const SizedBox(height: 30),
RaisedButton(
onPressed: () {
if (controllerName.text.isNotEmpty) {
Firestore.instance.collection('reg').add({'name':controllerName})
.then((result){
Navigator.pop(context);
controllerName.clear();
}).catchError((err) =>print(err));
}
},
child: const Text('Submit', style: TextStyle(fontSize: 20)),
),
],
),
),
),
);
}
}
答案 0 :(得分:0)
此行:
2
应替换为:
Firestore.instance.collection('reg').add({'name':controllerName})
此外,您可能应该给Firestore.instance.collection('reg').add({'name':controllerName.text})
一个空字符串的初始值,以使其不能为空。