我刚刚将 Flutter 升级到了最新版本(3.22.2),从那时起,我在配置 Firebase 项目时不断在 Firebase 提供的 firebase_options.dart 文件中收到此错误:
The library 'package:firebase_core/firebase_core.dart' doesn't export a member with the shown name 'FirebaseOptions'.
在文件中的这一行:
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
我尝试恢复旧的 Flutter 版本并重新安装,但仍然遇到问题。
我还尝试使用新的 Firebase 项目为 Web 应用程序创建一个新的 Flutter 项目,但仍然遇到相同的错误。
这是我尝试运行应用程序时遇到的错误
Error (Xcode): ../../../.pub-cache/hosted/pub.dev/firebase_core-3.2.0/lib/firebase_core.dart:8:8: Error: Error when reading '../../../.pub-cache/hosted/pub.dev/firebase_core_platform_interface-5.1.0/lib/firebase_core_platform_interface.dart': Permission denied
Could not build the application for the simulator.
Error launching application on iPhone 15 Pro Max.
以防万一,这里是 firebase_options.dart 代码:
// File generated by FlutterFire CLI.
// ignore_for_file: type=lint
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;
/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
...
抱歉,如果我的英语不好,我是法国人
确保您的 firebase_core 软件包是最新版本。
在 IDE 的终端中运行这些命令:
flutter pub outdated
那么,
flutter pub upgrade