lundi 18 janvier 2021

Firebase/Flutter: MissingPluginException – No implementation found for method

I recently wanted to add web support to my flutter project but I'm encountering a lot of problems.

When launching the application on Chrome, trying to connect I get an error:

"MissingPluginException(No implementation found for method signInWithCredential on channel 
plugins.flutter.io/firebase_auth)"

same error when creating an account:

"MissingPluginException(No implementation found for method createUserWithEmailAndPassword on channel plugins.flutter.io/firebase_auth)". 

I don't know if it comes from firebase / from a problem with the plugins on web support or from the versions of the plugins (I've already tried to modify the versions but always the same errors).

It's working fine for Android and IOS

I have already tried to :

  • recreate the web application on firebase
  • change plugin versions
  • flutter clean / flutter packages get
  • make flutter create . again in a new copy of my application repository

This is the auth.dart file:

import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';

abstract class BaseAuth {

  Future<String> currentUser();
  Future<String> signIn(String email, String password);
  Future<String> createUser(String email, String password);
  Future<void> signOut();
}

class Auth implements BaseAuth {
  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  Future<String> signIn(String email, String password) async {
    FirebaseUser user = (await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password)).user;
    return user.uid;
  }

  Future<String> createUser(String email, String password) async {
    FirebaseUser user = (await FirebaseAuth.instance.createUserWithEmailAndPassword(email: email, password: password)).user;
    return user.uid;
  }

  Future<String> currentUser() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user != null ? user.uid : null;
  }

  Future<String> currentUserMail() async {
    FirebaseUser user = await _firebaseAuth.currentUser();
    return user != null ? user.email : null;
  }

  Future<void> signOut() async {
    return _firebaseAuth.signOut();
  }

}

This is the flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.25.0-8.3.pre, on Linux, locale fr_FR.UTF-8)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed
      instructions).
      If the Android SDK has been installed to a custom location, please use
      flutter config --android-sdk to update to that location.

[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] VS Code (version 1.49.2)
[✓] Connected device (1 available)

This is the Web body:

<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('flutter-first-frame', function () {
        navigator.serviceWorker.register('flutter_service_worker.js');
      });
    }
  </script>
<!-- TODO: Add SDKs for Firebase products that you want to use
    https://firebase.google.com/docs/web/setup#available-libraries -->

    <script>
    // Your web app's Firebase configuration
    var firebaseConfig = {
      apiKey: "....",
      authDomain: "....",
      databaseURL: "....,
      projectId: "....,
      storageBucket: "....",
      messagingSenderId: "....",
      appId: "...."
    };
    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
  </script>
  <script src="https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js%22%3E</script>
  <script src="main.dart.js" type="application/javascript"></script>
</body>

This is the main.dart:

import 'dart:io';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:synthiaapp/Pages/Settings.dart';
import 'package:synthiaapp/Widgets/LocalNotifications.dart';
import 'root_page.dart';
import 'auth.dart';
// Import pages for navBar
import 'Pages/HomePage.dart';
import 'Pages/AccountPage.dart';
//import 'Pages/TestPage.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Synthia App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: RootPage(auth: new Auth()),
    );
  }
}

This is my pubspec.yaml :

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  dio: ^3.0.9
  path_provider: ^1.6.5
  sliding_switch: ^0.0.3
  percent_indicator: ^2.1.7+3
  permission_handler: ^4.4.0+hotfix.2
  open_file: ^3.0.1
  flutter_local_notifications: ^1.3.0
  firebase_core: ^0.4.0+9
  firebase_auth: ^0.14.0+5
  cloud_firestore: ^0.12.9+5
  provider: ^4.1.2
  uuid: ^2.0.4
  date_picker_timeline: ^1.2.1
  fitted_text_field_container: ^1.3.1+1
  flutter_email_sender: ^3.0.1
  cloud_functions: ^0.5.0
  intl: ^0.16.1
  firebase_messaging: ^5.0.2
  zefyr:
    git:
      url: https://github.com/memspace/zefyr.git
      path: packages/zefyr/
      commit: 9b032d8
  quill_delta: 1.0.2
  cupertino_icons: ^0.1.3
  http: ^0.12.0+2
  url_launcher: ^5.4.0



Aucun commentaire:

Enregistrer un commentaire