Firebase身份验证导致Flutter应用崩溃

时间:2020-04-05 22:59:52

标签: firebase flutter firebase-authentication

我刚刚启动了一个新的Flutter应用,所以蜜蜂还没有真正完成任何工作。我已将firebase_core:添加到我的pubspec.yaml文件中,没有错误,并且该应用程序可以正常启动。当我添加firebase_auth:时,会出现此错误:

Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Xcode build done.                                           21.9s
    path: satisfied (Path is satisfied), interface: en0
Configuring the default Firebase app...
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23e3dcce __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50b3b9b2 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23e3db0c +[NSException raise:format:] + 188
    3   Runner                              0x0000000109e60912 +[FIRApp configure] + 130
    4   Runner                              0x0000000109f2fcd9 -[FLTFirebaseAuthPlugin init] + 217
    5   Runner                              0x0000000109f2fa9b +[FLTFirebaseAuthPlugin registerWithRegistrar:] + 171
    6   Runner                              0x0000000109dfbc13 +[GeneratedPluginRegistrant registerWithRegistry:] + 115
    7   Runner                            <…>
Exited

到目前为止,该软件包还存在许多其他问题。发生什么事了?

2 个答案:

答案 0 :(得分:0)

我认为您忘记了最后(7)个步骤: https://pub.dev/packages/google_sign_in#ios-integration

您必须为每个登录方法在Info.plist中添加CFBundleTypeRoles。 此示例适用于Google登录。

<!-- Put me in the [my_project]/ios/Runner/Info.plist file -->
<!-- Google Sign-in Section -->
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <!-- TODO Replace this value: -->
            <!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
            <string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string>
        </array>
    </dict>
</array>
<!-- End of the Google Sign-in Section -->

使用您的GoogleService-Info.plist中的那个REVERSED_CLIENT_ID更改

我回家可以为您提供帮助。我有同样的错误,这就是解决方法。

答案 1 :(得分:0)

如果您已向Flutter项目中添加了function App() { const [cards, setCards] = useState([]); const addNewCard = cardInfo => { setCards(cards.concat(cardInfo)); }; const removeCard = key => { setCards(cards.slice(0, key).concat(cards.slice(key + 1, cards.length))) }; return ( <div> <Form onSubmit={addNewCard} /> <CardList cards={cards} handleClick={removeCard} /> </div> ); } const CardList = props => ( <div> {props.cards.map((card, index) => ( <Card {...card} key={index} handleClick={props.handleClick(index)} /> ))} </div> ); const Card = props => { return ( <div style={{ margin: "1em" }}> <img alt="avatar" style={{ width: "70px" }} src={props.avatar_url} /> <div> <div style={{ fontWeight: "bold" }}>{props.name}</div> <div>{props.blog}</div> <a href={props.html_url}>{props.html_url}</a> <button onClick={props.handleClick}>Delete</button> </div> </div> ); }; 个软件包,则应将从Firebase控制台下载的firebase添加到Xcode项目中。另外,请确保您的GoogleService-Info.plistbundle id (com.companyname.appname) firebase iOS project相同。

请检查此链接以了解Firebase抖动设置:https://firebase.google.com/docs/flutter/setup