prabinlamsal19
prabinlamsal19

Reputation: 109

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

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)?'.

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. 

Upvotes: 2

Views: 1934

Answers (3)

Spixz
Spixz

Reputation: 291

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.

Upvotes: 5

krishnaacharyaa
krishnaacharyaa

Reputation: 24902

Run

flutter pub upgrade --major-versions

Upvotes: 5

shobhonk
shobhonk

Reputation: 656

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

Upvotes: 1

Related Questions