after updating flutter, Firebase.initializeApp() does not seem to work on my phone anymore

446

Solution 1

I don't what happend now but when i started the app again on my phone it worked. Yesterday i did a couple of things maybe that was the cause. I copy and pasted new sha1 and sha256 finger prints on Firebase Authentication. I found the solution on Firebase phone authentication is not working on Android real device

Solution 2

Do you give permission for internet in Manifest file of an android?

Share:
446
FDjawid
Author by

FDjawid

Right now student of Information & Technology at Windesheim Flevoland.

Updated on January 02, 2023

Comments

  • FDjawid
    FDjawid over 1 year

    I updated the flutter to the latest version today and after that the app is not loading on real device because something is going wrong with Firebase.initializeApp().

    It does seem to still work on the android emulator but not on real device.

    This is the main.dart:

    import 'dart:io';
    
    import 'package:flutter/material.dart';
    import 'package:firebase_core/firebase_core.dart';
    import 'package:major_capital_mobile_app/pages/login_page.dart';
    
    void main() {
      HttpOverrides.global = MyHttpOverrides();
      WidgetsFlutterBinding.ensureInitialized();
      runApp(const App());
    }
    
    class App extends StatefulWidget {
      const App({Key? key}) : super(key: key);
    
      // Create the initialization Future outside of `build`:
      @override
      _AppState createState() => _AppState();
    }
    
    class MyHttpOverrides extends HttpOverrides {
      @override
      HttpClient createHttpClient(SecurityContext? context) {
        return super.createHttpClient(context)
          ..badCertificateCallback =
              (X509Certificate cert, String host, int port) => true;
      }
    }
    
    class _AppState extends State<App> {
      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 const Center(
                child:
                    Text('Not able to load app', textDirection: TextDirection.ltr),
              );
            }
    
            // Show app once complete
            if (snapshot.connectionState == ConnectionState.done) {
              return MaterialApp(
                title: 'Verification of phone',
                debugShowCheckedModeBanner: false,
                theme: ThemeData(
                    primaryColor: Colors.black,
                    primarySwatch: Colors.blue,
                    inputDecorationTheme: const InputDecorationTheme(
                        labelStyle: TextStyle(color: Colors.grey)),
                    backgroundColor: Colors.black),
                home: const LoginPage(),
              );
            }
    
            // Else wait until initialization
            return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        CircularProgressIndicator(
                          color: Colors.lime,
                          backgroundColor: Theme.of(context).primaryColor,
                        )
                      ])
                ]);
          },
        );
      }
    }
    
    

    And this is the pubspec.yaml file:

    name: major_capital_mobile_app
    description: A new Flutter project.
    
    # The following line prevents the package from being accidentally published to
    # pub.dev using `flutter pub publish`. This is preferred for private packages.
    publish_to: 'none' # Remove this line if you wish to publish to pub.dev
    
    # The following defines the version and build number for your application.
    # A version number is three numbers separated by dots, like 1.2.43
    # followed by an optional build number separated by a +.
    # Both the version and the builder number may be overridden in flutter
    # build by specifying --build-name and --build-number, respectively.
    # In Android, build-name is used as versionName while build-number used as versionCode.
    # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
    # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
    # Read more about iOS versioning at
    # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
    version: 1.0.0+1
    
    environment:
      sdk: ">=2.14.0 <3.0.0"
    
    # Dependencies specify other packages that your package needs in order to work.
    # To automatically upgrade your package dependencies to the latest versions
    # consider running `flutter pub upgrade --major-versions`. Alternatively,
    # dependencies can be manually updated by changing the version numbers below to
    # the latest version available on pub.dev. To see which dependencies have newer
    # versions available, run `flutter pub outdated`.
    dependencies:
      flutter:
        sdk: flutter
    
    
    
      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
    
      cupertino_icons: ^1.0.2
      firebase_core: ^1.7.0
      firebase_auth: ^3.1.2
      cloud_firestore: ^2.5.3
      email_auth: ^1.0.0
      hexcolor: ^2.0.5
      fluttertoast: ^8.0.8
      cloud_functions: ^3.0.4
      device_info: ^2.0.2
      package_info: ^2.0.2
      provider: ^6.0.1
      get: ^4.3.8
      syncfusion_flutter_charts: ^19.3.48
      google_fonts: ^2.1.0
      expandable: ^5.0.1
      charts_flutter: ^0.12.0
      font_awesome_flutter: ^9.2.0
      chartjs: ^0.6.0
      fl_chart: ^0.40.2
      desktop_window: ^0.4.0
      syncfusion_flutter_datagrid: ^19.3.53
      http: ^0.13.4
      shared_preferences: ^2.0.8
      mockito: ^5.0.16
      rxdart: ^0.27.3
      pinput: ^1.2.2
      auto_size_text: ^3.0.0
    
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    
      # The "flutter_lints" package below contains a set of recommended lints to
      # encourage good coding practices. The lint set provided by the package is
      # activated in the `analysis_options.yaml` file located at the root of your
      # package. See that file for information about deactivating specific lint
      # rules and activating additional ones.
      flutter_lints: ^1.0.0
    
    # For information on the generic Dart part of this file, see the
    # following page: https://dart.dev/tools/pub/pubspec
    
    # The following section is specific to Flutter.
    flutter:
      assets:
        - assets/data.json
        - assets/rounded.png
        - assets/mcm_white_logo.png
        - treeline2_Tekengebied.png
        - b_a_token.png
        - binance_coin.png
        - bitcoin.png
        - ethereum.png
    
      # The following line ensures that the Material Icons font is
      # included with your application, so that you can use the icons in
      # the material Icons class.
      uses-material-design: true
    
    
      # To add assets to your application, add an assets section, like this:
      # assets:
      #   - images/a_dot_burr.jpeg
      #   - images/a_dot_ham.jpeg
    
      # An image asset can refer to one or more resolution-specific "variants", see
      # https://flutter.dev/assets-and-images/#resolution-aware.
    
      # For details regarding adding assets from package dependencies, see
      # https://flutter.dev/assets-and-images/#from-packages
    
      # To add custom fonts to your application, add a fonts section here,
      # in this "flutter" section. Each entry in this list should have a
      # "family" key with the font family name, and a "fonts" key with a
      # list giving the asset and other descriptors for the font. For
      # example:
      fonts:
      - family: CustomIcons
        fonts:
          - asset: lib/icons/fonts/CustomIcons.ttf
    
      #
      # For details regarding fonts from package dependencies,
      # see https://flutter.dev/custom-fonts/#from-packages
    
    

    Like i said it seems to work on android emulator but once i try it on real device i get the message not able to load app on the screen so it seems it can load the app but its not successfully doing initiliazation of Firebase.initializeApp(). to show the whole app.

  • FDjawid
    FDjawid over 2 years
    i don't know what you mean
  • FDjawid
    FDjawid over 2 years
    i have this inside android\app\src\main\AndroidManifest.xml
  • FDjawid
    FDjawid over 2 years
    yes the permission is therre
  • FDjawid
    FDjawid over 2 years
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mcma.major_capital_mobile_app"> <!-- Flutter needs it to communicate with the running application to allow setting breakpoints, to provide hot reload, etc. --> <uses-permission android:name="android.permission.INTERNET"/> </manifest> The permission is there but its still not working