: assert(map['apiKey'] != null, "'apiKey' cannot be null."),

i'm trying to develop an app on Android studio, with firebase tools. Despite i have a file in the lib firebase_options (created with flutterfire configure), it always give me error:

E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:firebase_core_platform_interface/src/firebase_options.dart': Failed assertion: line 61 pos 16: 'map['apiKey'] != null': 'apiKey' cannot be null.
    #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
    #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
    #2      new FirebaseOptions.fromMap (package:firebase_core_platform_interface/src/firebase_options.dart:61:16)
    #3      MethodChannelFirebase._initializeFirebaseAppFromMap (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:45:23)
    #4      ListMixin.forEach (dart:collection/list.dart:86:13)
    #5      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:35:10)
    <asynchronous suspension>
    #6      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:7)
    <asynchronous suspension>
    #7      Firebase.initializeApp (package:firebase_core/src/firebase.dart:40:31)
    <asynchronous suspension>
    #8      main (package:my_firstapp/main.dart:13:3)
    <asynchronous suspension> 

my main.dart is :

import 'package:flutter/material.dart';
import 'package:my_firstapp/locator.dart';
import 'package:my_firstapp/models/user_model.dart';
import 'package:my_firstapp/screens/wrapper.dart';
import 'package:provider/provider.dart';
import 'package:my_firstapp/services/auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';


void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,
  );
  setupServices();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return StreamProvider<UserModel>.value(
      value: AuthService().user,
      initialData: null,
      child: MaterialApp(
        theme: ThemeData(
          primaryColor: Color(0xff5FA55A),
          secondaryHeaderColor: Color(0xff5FA55A),
        ),
        home: Wrapper(),
      ),
    );
  }
}

What can i do, i'm stuck on this problem. Please help me

1 answer

  • answered 2022-05-04 11:08 Sharon

    The API key is missing from the firebase_options file. Open the firebase_options file, check line 61 and also Ctrl+f 'apiKey' to find other mentions in the file where it's missing.

    To find the API key:

    1. The Android app Api key can be found in the google-services.json file.
    2. The ios app Api key can be found in the GoogleService-Info.plist
    3. For the web app, go to the firebase console, select project settings from the menu.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum