【问题标题】:Flutter: MissingPluginException(No implemention found for method currentUser on channel plugins.flutter.io/firebase_auth) for iOSFlutter:iOS 的 MissingPluginException(在通道 plugins.flutter.io/firebase_auth 上找不到方法 currentUser 的实现)
【发布时间】:2019-09-10 21:37:48
【问题描述】:

不知道是什么异常,以前id没显示,现在显示了!

此代码在 StartPage 上,它通过检查 uid 是否为 null 来检查用户是否登录,如果他登录则转换为 HomePage,否则转换为 SignInPage。

我自己无法解决这个问题,我尝试了不止一件事来解决这个错误。 由于这个错误,我的应用程序已损坏。


  Widget build(BuildContext context) {
    return FutureBuilder<User>(
        future: setUser(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            if (snapshot.data.uid != null) {
              return DefaultTabController(
                length: 2,
                child: Scaffold(
                  appBar: _buildAppBar(),
                  body: _buildTabView(context),
                ),
              );
            }
            return HomePage(
              user: snapshot.data,
            );
          }
          return Scaffold(
            backgroundColor: Colors.white,
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  !snapshot.hasError
                      ? SpinKitCircle(
                          color: Theme.of(context).primaryColor,
                          size: 50,
                        )
                      : Icon(
                          Icons.warning,
                          color: Theme.of(context).primaryColor,
                          size: 50,
                        ),
                  Text(
                    !snapshot.hasError
                        ? "يرجى الانتظار..."
                        : "مشكلة!" + "\n${snapshot.error.toString()}",
                    style: TextStyle(color: Colors.black54),
                    textDirection: TextDirection.rtl,
                    textAlign: TextAlign.center,
                  )
                ],
              ),
            ),
          );
        });
  }

setUser 方法:


Future<User> getUserData() async {
    User user;
    final FirebaseUser authUser = await FirebaseAuth.instance.currentUser();
    String uid = authUser.uid;
    DocumentSnapshot ds = await Firestore.instance.collection('Users').document('$uid').get();
    user = User(
      name: ds['name'],
      email: ds['email'],
      hospital: ds['hospital'],
      password: ds['password'],
      phoneNumber: ds['phone'],
      rank: ds['rank'],
      uid: uid,
    );
    return user;
  }

【问题讨论】:

  • 您是否尝试过完全重建代码而不是 Hot Reload?也可以试试Flutter Clean 看看是否有帮助。或者,已在此处发布与您面临的问题类似的建议:github.com/flutter/flutter/issues/14137
  • @Muhammad Hasan Alasady 。你能解决这个问题吗?在尝试在 iOS 上运行应用程序时,我也面临同样的问题。

标签: flutter dart firebase-authentication


【解决方案1】:

https://github.com/flutter/flutter/issues/36958

解决方案:我从 Firebase 应用设置页面复制了 AppDelegate.m。如果没有插件,这可以正常工作,但是一旦您开始添加插件就会导致 MissingPluginException。正确的代码是:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
@import UIKit;
@import Firebase;

@implementation AppDelegate

(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[FIRApp configure];
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application 
didFinishLaunchingWithOptions:launchOptions];
//return YES;
}

【讨论】:

  • 我已经尝试过了,但没有运气可能是因为我还有其他插件。而且我们不能只有一个插件,应用程序中会有其他插件。我们需要一个也可以与其他插件一起使用的解决方案。
猜你喜欢
  • 2019-09-06
  • 2020-08-18
  • 2020-10-20
  • 2020-08-10
  • 2020-12-09
  • 2021-05-18
  • 2021-09-12
  • 1970-01-01
相关资源
最近更新 更多