Firebase Auth Web Error. Error: The argument type 'Future<void> Function()' can't be assigned to the parameter type 'Future<void> Function(App)?'

huangapple go评论74阅读模式
英文:

Firebase Auth Web Error. Error: The argument type 'Future<void> Function()' can't be assigned to the parameter type 'Future<void> Function(App)?'

问题

首先,这是我遇到的错误:

/C:/Users/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_auth_web-5.2.2/lib/firebase_auth_web.dart:92:45: 错误: 参数类型 'Future<void> Function()' 不能分配给参数类型 'Future<void> Function(App)?'。

  • 'Future' 来自 'dart:async'。
  • 'App' 来自 'package:firebase_core_web/src/interop/app.dart'('/C:/Users/Grace%20Computer/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core_web-2.2.2/lib/src/interop/app.dart')。
    app.dart:1
    FirebaseCoreWeb.registerService('auth', () async {
    ^

编译应用程序失败。

我正在尝试在Web上运行一个Flutter登录应用程序。我已经将所需的凭证粘贴为<script>在web>index.html文件中。main.dart文件如下:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
      options: const FirebaseOptions(
          apiKey: "AIzaSyDZvxw2LXy05hLkcH_fpPWWa5RzwVlbQro",
          projectId: "messageapp-acf7a",
          messagingSenderId: "72207922701",
          appId: "1:72207922701:web:d84fe3144a7f2de5dd4744"
      ),
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: SignupPage(),
    );
  }
}

pubspec.yaml文件的相关部分如下:

name: frontend_msngr
description: 一个新的Flutter项目。
publish_to: 'none' # 如果您希望发布到pub.dev,请删除此行

version: 1.0.0+1

environment:
  sdk: '>=2.19.2 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  chat_bubbles: 
  firebase_core: 
  cupertino_icons: ^1.0.2
  firebase_auth: 
  firebase_auth_web:

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true

由于出现错误的文件是lib/firebase_auth_web.dart,我不知道如何传递了不正确的参数(如错误所建议)。

我尝试稍微更改了版本,但对我没有起作用。

英文:

First of all, this is the error that I encountered:

> /C:/Users/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_auth_web-5.2.2/lib/firebase_auth_web.dart:92:45: Error: The argument type 'Future<void> Function()' can't be assigned to the parameter type 'Future<void> Function(App)?'.

  • 'Future' is from 'dart:async'.
  • 'App' is from 'package:firebase_core_web/src/interop/app.dart' ('/C:/Users/Grace%20Computer/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core_web-2.2.2/lib/src/interop/app.dart').
    app.dart:1
    FirebaseCoreWeb.registerService('auth', () async {
    ^

> Failed to compile application.

I am trying to run a flutter login application on web. I have pasted the required creditentials as <script> on the web>index.html file. The main.dart file looks like this:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
      options: const FirebaseOptions(
          apiKey: &quot;AIzaSyDZvxw2LXy05hLkcH_fpPWWa5RzwVlbQro&quot;,
          projectId: &quot;messageapp-acf7a&quot;,
          messagingSenderId: &quot;72207922701&quot;,
          appId: &quot;1:72207922701:web:d84fe3144a7f2de5dd4744&quot;
          ),
          );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: SignupPage(),
    );
  }
}

The relevant parts of pubspec.yaml file is this:

name: frontend_msngr
description: A new Flutter project.
publish_to: &#39;none&#39; # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: &#39;&gt;=2.19.2 &lt;3.0.0&#39;


dependencies:
  flutter:
    sdk: flutter
  chat_bubbles: 
  firebase_core: 
  cupertino_icons: ^1.0.2
  firebase_auth: 
  firebase_auth_web:

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0

flutter:

  uses-material-design: true```

Since,the file that got the error is lib/firebase_auth_web.dart , I don&#39;t know how I passed incorrect parameters (as suggested by the error).



I tried changing the versions a bitbut it didn&#39;t work for me. 

</details>


# 答案1
**得分**: 5

运行
flutter pub upgrade --major-versions


<details>
<summary>英文:</summary>

Run

flutter pub upgrade --major-versions


</details>



# 答案2
**得分**: 5

```yaml
dependencies:
  flutter:
    sdk: flutter
  firebase_auth: 4.3.0
  intl: 0.17.0

你需要将 firebase_auth 版本升级到最新版本(4.3.0,2023年3月)。为了与 firebase_auth 4.3.0 的依赖关系匹配,我不得不降级 intl 到版本 0.17.0。然后只需运行 flutter pub get

flutter pub upgrade --major-versions 并没有为我升级这些包,它只是提醒我有一些包有新版本可用。


<details>
<summary>英文:</summary>

dependencies:
flutter:
sdk: flutter
firebase_auth: 4.3.0
intl: 0.17.0


You need to upgrade your version of `firebase_auth` to the last one (4.3.0 mars 2023) in your `pubspec.yaml`. I had to downgrade `intl` to the version `0.17.0` to fit with the dependence with `firebase_auth 4.3.0`.  And after just run `flutter pub get`.


`flutter pub upgrade --major-versions` didn&#39;t upgrade the packages for me but just notice me that there is new versions for some of my packages.

</details>



# 答案3
**得分**: 1

这是过去我曾使用过并且运行良好的代码示例:

```dart
Future<void> main() async {
  runApp(App());
}

class App extends StatelessWidget {
  // 在`build`之外创建初始化 Future:
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // 初始化 FlutterFire:
      future: _initialization,
      builder: (context, snapshot) {
        // 检查错误
        if (snapshot.hasError) {
          return showAlertDialog(context, snapshot.error.toString());
        }

        // 当完成时,显示您的应用程序
        if (snapshot.connectionState == ConnectionState.done) {
          // 成功后调用方法
        }
        // 否则,在等待初始化完成时显示某些内容,例如加载屏幕
        return Loading();
      },
    );
  }
}

pubspec.yaml 文件的一部分:

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  
  firebase_auth: ^1.0.1

dev_dependencies:
  flutter_test:
    sdk: flutter

请注意,我已经删除了您原始文本中的 HTML 实体编码,以便更清晰地查看代码。

英文:

This I have used in the past and worked well

Future&lt;void&gt; main() async {
  runApp(App());
}

class App extends StatelessWidget {
  // Create the initilization Future outside of `build`:
  final Future&lt;FirebaseApp&gt; _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire:
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          return showAlertDialog(context, snapshot.error.toString());
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
			//Call method once successful
        }
        // Otherwise, show something whilst waiting for initialization to complete. for example loading screen
        return Loading();
      },
    );
  }
}

Snippit of the pubsec file

environment:
  sdk: &quot;&gt;=2.7.0 &lt;3.0.0&quot;

dependencies:
  flutter:
    sdk: flutter


  
  firebase_auth: ^1.0.1
dev_dependencies:
  flutter_test:
    sdk: flutter

huangapple
  • 本文由 发表于 2023年3月12日 18:32:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定