如何将我在 android studio 中的 flutter 应用程序与我在 firebase 中的数据库连接起来?在控制台中运行代码在移动 SDK 上运行良好。但是如果您将一项写入添加项字段,则会出现以下错误:
======== Exception caught by gesture ===============================================================
The following NoSuchMethodError was thrown while handling a gesture:
The method 'setZigarren' was called on null.
Receiver: null
Tried calling: setZigarren("h", false)
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _humidorState.addZigarren (package:zigarre/humidor.dart:18:14)
#2 _AddItemDialogState.save (package:zigarre/add_item_dialog.dart:19:25)
#3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
#4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#874b7
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(193.8, 290.5)
finalLocalPosition: Offset(41.4, 6.9)
button: 1
sent tap down
====================================================================================================
代码:方法 setZigarren
import 'package:cloud_firestore/cloud_firestore.dart';
class DatabaseService {
final String userID;
DatabaseService(this.userID);
final CollectionReference userZigarren = Firestore.instance.collection('userZigarren');
Future setZigarren(String key, bool value) async {
return await userZigarren.document(userID).setData(
{key: value}, merge: true);
}
Future deleteZigarren(String key) async {
return await userZigarren.document(userID).updateData({
key: FieldValue.delete(),
});
}
Future checkIfUserExists() async {
if ((await userZigarren.document(userID).get()).exists) {
return true;
} else {
return false;
}
}
}
答案 0 :(得分:0)
我终于明白了。只需要重新启动android studio。这往往太简单了。