Flutter:MissingPluginException(在通道plugins.flutter.io/firebase_auth上未找到方法currentUser的实现)

时间:2019-09-10 21:37:48

标签: flutter dart firebase-authentication

我不知道它是什么异常,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;
  }

1 个答案:

答案 0 :(得分:0)

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;
}