简体   繁体   English

I/flutter (22027): MissingPluginException(在通道 plugins.flutter.io/cloud_firestore 上找不到方法 DocumentReference#setData 的实现)

[英]I/flutter (22027): MissingPluginException(No implementation found for method DocumentReference#setData on channel plugins.flutter.io/cloud_firestore)

Future<void> _getUserData() async {
  final database = Firestore.instance;
  try {
    FirebaseUser _currentUser = await FirebaseAuth.instance.currentUser();
    String authid =_currentUser.uid;
    String email = _currentUser.email;
    Map<String, String> userData = {
      'AuthUserId':'$authid',
      'Email':'$email',
      'FullName': '',
      'MobileNum': '',
      'Address': '',
      'City/Village': '',
      'District': '',
      'State': '',
      'PinCode': '',
    };
   database.collection('UserData').add(userData).catchError((e) {
     print(e);
    });
 } catch (e) {
    print(e);
 }
}
@override
void initState() {
    super.initState();
    _getUserData();
  }

"I am trying to insert the data into the cloud firestore and i have called this function in initState() but i ham getting error as i have mentioned above “我正在尝试将数据插入到云 Firestore 中,并且我已经在 initState() 中调用了这个函数,但是我遇到了上面提到的错误

Make sure you are using the latest cloud_firestore version.确保您使用的是最新的cloud_firestore版本。 Then execute:然后执行:

flutter clean
flutter packages get

Update, Starting since cloud_firestore version 0.14.0:更新,从cloud_firestore版开始:

setData() was replaced with set() . setData()替换为set() Other useful link:其他有用的链接:

The getter 'instance' isn't defined for the type 'Firestore' 未为“Firestore”类型定义 getter“实例”

for my case, I performed steps as below:就我而言,我执行了以下步骤:

flutter clean
flutter packages get

uninstall app卸载应用

update: /android/app/build.gradle更新:/android/app/build.gradle

defaultConfig {
    ...
    multiDexEnabled true
}

run again.再次运行。

hope this helps希望这可以帮助

I closed the IDE (Android Studio) and did flutter clean .我关闭了 IDE (Android Studio) 并做了flutter clean After that I restarted the IDE and created a new AVD.之后,我重新启动了 IDE 并创建了一个新的 AVD。 The MissingPluginException was gone after that and I had the following error:在那之后 MissingPluginException 消失了,我有以下错误:

D8: Cannot fit requested classes in a single dex file

I fixed this adding multiDexEnabled true to the defaultConfig in /android/app/build.gradle我修复了将multiDexEnabled true添加到multiDexEnabled true中的defaultConfig的问题

defaultConfig {
    ...
    multiDexEnabled true
}

I don't know if this is releated to your problem, but thats how I solved the error.我不知道这是否与您的问题有关,但这就是我解决错误的方法。

My problem was caused by editing the firebase instance settings after I've used the firestore in the previous page which u can't do and it didn't give me the correct error for it until I delete this folder我的问题是由于在上一页中使用了 firestore 后编辑了 firebase 实例设置而引起的,而您无法这样做,并且在我删除此文件夹之前它没有给我正确的错误

%AppData%\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_core_platform_interface-2.0.0

and then It correctly gave me the error and so I just applied the settings in main.dart然后它正确地给了我错误,所以我只是应用了 main.dart 中的设置

Widget build(BuildContext context) 
{
   return FutureBuilder(
      future: Firebase.initializeApp(),
      builder: (context, snapshot) 
      {
         if (snapshot.hasError) {
            return Text('error');
         }

         if (snapshot.connectionState == ConnectionState.done) {
            FirebaseFirestore.instance.settings = Settings(
            persistenceEnabled: true,
            cacheSizeBytes: Settings.CACHE_SIZE_UNLIMITED,
            );

          return MaterialApp(....
         }
      }
   );
}

Stop the running app and rerun.停止正在运行的应用程序并重新运行。 It may be because you added the firestore dependency while the app is already running in debug mode.这可能是因为您在应用程序已经在调试模式下运行时添加了 firestore 依赖项。 In this case the hot reload or restart will not work if you to call methods of newly added dependency.在这种情况下,如果您调用新添加的依赖项的方法,则热重载或重新启动将不起作用。 You have to stop the running app and rerun.您必须停止正在运行的应用程序并重新运行。 (This solved my issue). (这解决了我的问题)。

Do this before rerunning.在重新运行之前执行此操作。 - flutter clean - flutter packages get - flutter clean - flutter 包得到

If you are working on Visual Studio Code and you are running your project on an IOS simulator, then it might not work.如果您正在使用 Visual Studio Code 并且在 IOS 模拟器上运行您的项目,那么它可能无法正常工作。 You can run your project from Xcode and it will work with no issues, you have to open the file that is .xcworkspace.您可以从 Xcode 运行您的项目,它可以正常工作,您必须打开 .xcworkspace 文件。

I tried this and it helped me我试过这个,它帮助了我

flutter clean
flutter packages get

Later, Uninstall App and try reinstalling it ✌🏻稍后,卸载应用程序并尝试重新安装它✌🏻

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MissingPluginException(未找到方法 DocumentReference#get on channel plugins.flutter.io/firebase_firestore 的实现) - MissingPluginException(No implementation found for method DocumentReference#get on channel plugins.flutter.io/firebase_firestore) Flutter Web:MissingPluginException(在频道 plugins.flutter.io/firebase_auth 上找不到方法 startListeningAuthState 的实现) - Flutter Web: MissingPluginException(No implementation found for method startListeningAuthState on channel plugins.flutter.io/firebase_auth) Flutter MissingPluginException(在通道插件上找不到方法 loadInterstitialAd 的实现。flutter.io/firebase_admob) - Flutter MissingPluginException(No implementation found for method loadInterstitialAd on channel plugins.flutter.io/firebase_admob) MissingPluginException(在通道插件上找不到方法 FirebaseApp#appNamed 的实现。flutter.io/firebase_core) - MissingPluginException(No implementation found for method FirebaseApp#appNamed on channel plugins.flutter.io/firebase_core) 未处理的异常:MissingPluginException(在通道插件上找不到方法 X 的实现。flutter.io/Y) - Unhandled Exception: MissingPluginException(No implementation found for method X on channel plugins.flutter.io/Y) iOS:MissingPluginException(在通道插件上找不到方法 Firebase#initializeCore 的实现。flutter.io/firebase_core) - iOS: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core) MissingPluginException(在通道插件上找不到方法 getToken 的实现。flutter.io/firebase_messaging) - MissingPluginException(No implementation found for method getToken on channel plugins.flutter.io/firebase_messaging) 未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_messaging 上找不到方法 getToken 的实现) - Unhandled Exception: MissingPluginException(No implementation found for method getToken on channel plugins.flutter.io/firebase_messaging) MissingPluginException(在通道 plugins.flutter.io/firebase_auth 上没有找到方法 signInWithCredential 的实现) - MissingPluginException(No implementation found for method signInWithCredential on channel plugins.flutter.io/firebase_auth) 缺少插件异常(在通道插件上找不到方法 firebase#initializecore 的实现。flutter.io/firebase_core) - missingpluginexception(no implementation found for method firebase#initializecore on channel plugins.flutter.io/firebase_core)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM