gpt4 book ai didi

flutter - Flutter:MissingPluginException(在 channel plugins.flutter.io/firebase_auth上未找到方法currentUser的实现),适用于iOS

转载 作者:行者123 更新时间:2023-12-03 04:00:11 26 4
gpt4 key购买 nike

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

最佳答案

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

solution: I copied the AppDelegate.m from the firebase app setup page. This works fine if there are no plugins but causes the MissingPluginException as soon as you start adding plugins. Correct code is:


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

关于flutter - Flutter:MissingPluginException(在 channel plugins.flutter.io/firebase_auth上未找到方法currentUser的实现),适用于iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57878531/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com