我正在使用Cloud Firestore作为后端。我已经做了一个表格,想将其数据存储在数据库中。但是,当我按下“保存”按钮时,它会引发以下错误消息:
在处理手势时引发了以下NoSuchMethodError: 方法'call'在null上被调用。 接收者:null 尝试调用:call(“ xyz”)
这是我的代码:
import 'package:flutter/material.dart';
import 'dart:collection';
import 'package:cloud_firestore/cloud_firestore.dart';
class ListPlusForm extends StatefulWidget {
ListPlusForm({Key key}) : super(key: key);
@override
_ListPlusFormState createState() => _ListPlusFormState();
}
class _ListPlusFormState extends State<ListPlusForm> {
final _formKey = GlobalKey<FormState>();
String _itemName;
double _progress = 0;
DateTime _start = new DateTime.now();
DateTime _due;
int _id = 123;
bool _sliderSwitch;
bool _reminderSwitch;
bool _prioritySwitch;
@override
Widget build(BuildContext context) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: 235,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(20.0),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.white, Colors.grey[400]],
),
),
child: Form(
key: _formKey,
child: Stack(
children: [
Positioned(
top: 10,
left: 10,
child: Container(
width: 200,
child: TextFormField(
style: TextStyle(
fontSize: 15,
),
decoration: InputDecoration(
hintText: 'Name?',
),
onSaved: (val) => {
setState(() => _itemName = val),
}),
),
),
Positioned(
top: 60,
left: 10,
child: Row(
children: [
Text('Need a slider?'),
Switch(
value: true,
onChanged: (value) => {
setState(() => _sliderSwitch),
},
),
Text('Need a reminder?'),
Switch(
value: true,
onChanged: (value) => {
_reminderSwitch = value,
},
),
],
),
),
Positioned(
top: 90,
left: 10,
child: Row(
children: [
Container(
width: 200,
child: TextFormField(
style: TextStyle(
fontSize: 15,
),
decoration: InputDecoration(
hintText: 'Due when?',
),
onTap: () => {
showDatePicker(
context: context,
initialDate: _start,
firstDate: _start,
lastDate: DateTime(2025))
.then(
(due) {
setState(
() {
_due = due;
},
);
},
),
},
),
),
Text('This a priority?'),
Switch(
value: true,
onChanged: (value) => {
_prioritySwitch = value,
},
),
],
),
),
Positioned(
top: 140,
left: 10,
child: Row(
children: [],
),
),
Positioned(
bottom: 5,
left: 65,
child: Container(
width: 200,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
const Color(0xFF5761B2),
const Color(0xFF1FC588),
]),
),
child: MaterialButton(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_circle),
Text('Add item'),
]),
onPressed: () => {
setState(() {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
Map<dynamic, dynamic> listItem =
new HashMap<dynamic, dynamic>();
listItem["Description"](_itemName);
listItem["Due"](_due);
listItem["ID"](_id);
listItem["Priority"](_prioritySwitch);
listItem["Progress"](_progress);
listItem["Reminder"](_reminderSwitch);
listItem["SliderSwitch"](_sliderSwitch);
listItem["Start"](_start);
Future<void> uploadingData(
var _itemName,
var _due,
var _id,
bool _prioritySwitch,
var _progress,
bool _reminderSwitch,
bool _sliderSwitch) async {
await Firestore.instance
.collection("Task Lists")
.add(listItem);
}
}
;
}),
},
),
))
],
),
),
),
);
}
}
谢谢!
答案 0 :(得分:1)
问题是您调用了HashMap的键而不是将其归因于
ip2 = open('rotten', 'r')
ipList1 = [line.strip().replace('\n', '') for line in ip1]
ipList2 = [line.strip().replace('\n', '') for line in ip2]
ip1.close()
ip2.close()
newlist = []
for v in ip1:
if v not in ip2:
newlist.append(v)
c = open('end', 'w')
c.write('\n'.join(newlist))
c.close()
更改
listItem["Description"](_itemName);
listItem["Due"](_due);
listItem["ID"](_id);
listItem["Priority"](_prioritySwitch);
listItem["Progress"](_progress);
listItem["Reminder"](_reminderSwitch);
listItem["SliderSwitch"](_sliderSwitch);
listItem["Start"](_start);