Firebase身份验证Web错误,错误:参数类型“Future< void>Function()”无法分配给参数类型“Future< void>Function(App)?”

ig9co6j1  于 2023-03-13  发布在  其他
关注(0)|答案(2)|浏览(120)

首先,这是我遇到的错误:
/C:/Users/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_auth_web-5.2.2/lib/firebase_auth_web.dart:92:45:错误:无法将参数类型“Future Function()”分配给参数类型“Future Function(App)?”。

  • “未来”来自“dart:async”。
  • “应用程序”来自“软件包:Firebase_core_web/src/互操作/应用程序.dart”('/C:/用户/Grace%20计算机/应用程序数据/本地/发布/缓存/托管/发布.开发/Firebase_core_web-2.2.2/库/src/互操作/应用程序. dart').应用程序.dart:1 Firebase_core_web.注册表服务('auth',()异步{ ^

未能编译应用程序。
我正在尝试运行一个flutter登录应用程序。我已经粘贴了所需的creditentials,如在web〉index.html文件。主.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: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to 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```

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


I tried changing the versions a bitbut it didn't work for me.
cunj1qz1

cunj1qz11#

flutter pub upgrade --major-versions
fnvucqvd

fnvucqvd2#

这个我过去用过,效果很好

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

class App extends StatelessWidget {
  // Create the initilization Future outside of `build`:
  final Future<FirebaseApp> _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();
      },
    );
  }
}

pubsec文件的代码段

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  
  firebase_auth: ^1.0.1
dev_dependencies:
  flutter_test:
    sdk: flutter

相关问题