【问题标题】:error: The argument type 'FirebaseApp' can't be assigned to the parameter type 'Firebase'错误:无法将参数类型“FirebaseApp”分配给参数类型“Firebase”
【发布时间】:2021-07-09 00:46:39
【问题描述】:
Future<void> main() async{
  WidgetsFlutterBinding.ensureInitialized();

  final FirebaseApp app = await Firebase.initializeApp();
  runApp(ProviderScope(child: MyApp(app:app)));
}


class MyApp extends StatelessWidget {

  FirebaseApp app;

  MyApp({this.app});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page',app:app),
    );
  }
}

编译时出现问题,它显示错误:参数类型“FirebaseApp”无法分配给参数类型“Firebase”。 (argument_type_not_assignable 在 [tingting_chat] lib\main.dart:28)。如何解决?

【问题讨论】:

  • 您不必将 firebase 应用实例向下传递到 Widget 树。
  • 我该如何解决? @HuthaifaMuayyad

标签: flutter dart


【解决方案1】:
@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
}

在应用程序的 gradle 中(文件末尾):

dependencies {
    ....
}

apply plugin: 'com.google.gms.google-services'

是项目的gradle:

   dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.0.0'
}

【讨论】:

    猜你喜欢
    • 2021-08-22
    • 2021-11-03
    • 2022-08-14
    • 2022-12-24
    • 2020-11-20
    • 2021-08-26
    • 2021-08-30
    • 1970-01-01
    • 2020-08-31
    相关资源
    最近更新 更多