skip to Main Content

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 Function()’ can’t be assigned to the parameter type ‘Future 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 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: "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(),
    );
  }
}

The relevant parts of pubspec.yaml file is this:

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. 

3

Answers


  1. This I have used in the past and worked well

    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();
          },
        );
      }
    }
    

    Snippit of the pubsec file

    environment:
      sdk: ">=2.7.0 <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter
    
    
      
      firebase_auth: ^1.0.1
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    Login or Signup to reply.
  2. Run

    flutter pub upgrade --major-versions
    
    Login or Signup to reply.
  3. 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’t upgrade the packages for me but just notice me that there is new versions for some of my packages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search