我在尝试运行 Firebase 应用程序时收到此错误。我已经尝试过
flutter upgrade
但没有解决该错误
我希望看到刷新后的 flutter 应用程序 UI,但运行 main.dart 后它给出了这个错误,解决方案似乎不在任何地方。
main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:gated/auth/auth.dart';
import 'package:gated/firebase_options.dart';
//import 'package:gated/auth/login_or_register.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: AuthPage(),
);
}
}
错误:
../../../../AppData/Local/Pub/Cache/hosted/pub.dev/auth-8.2.0+02/lib/src/auth.dart:481:44: Error: The argument type 'bool?' can't be assigned to the parameter type 'bool' because 'bool?' is nullable and 'bool' isn't.
appVerificationDisabledForTesting: appVerificationDisabledForTesting,
^
Target kernel_snapshot failed: Exception
请帮我解决这个问题!
正如@jamesdlin 指出的:package:auth 已停止使用。根据 GitHub 存储库,最近对存储库的提交是由另一个用户四个月前提交的;最后一次提交 pub.dev 版本是在 14 个月前。
所以我认为你有两个选择。
您可以直接从 git 存储库依赖包,如下所示:
auth:
git:
url: https://github.com/AndriousSolutions/auth.git
ref: f6f709c # The commit hash - usually first 7 digits are plenty
^ 这应该是您的直接替代品。请记住保持 yaml 格式正确。并确保替换您当前的 pubspec 行。您收到的错误引用了最新版本中已更改的行号:所以现在应该修复它。
这里的缺点是,如果你运行
flutter pub upgrade
或 flutter pub outdated
,它将不再找到 auth 包的任何更新,因为你不再从 pub 拉取 - 你是从 github 拉取,所以这取决于你保持最新。
现在还不清楚该软件包的前进方向是什么 - 我在 GitHub 或 pub.dev 页面上找不到任何帖子来解释如何迁移它或该软件包的任何未来计划。
因此,这在很大程度上是一种尽可能长久的情况,从长远来看,我建议您(a)分叉存储库并自己控制包,以使其保持最新以满足您的需求或 (b) 开始寻找替代方案...说到...
必须重新编写一些代码库并不理想,但看起来
auth
支持 firebase、google auth、facebook 和 twitter 作为官方登录选项。 firebase_auth
软件包似乎支持其软件包中的那些内容。因此,尝试迁移到 package:firebase_auth 是一个很好的起点。
这样做的好处是,通过切换到仍在维护的包,您将来不太可能遇到此类问题,因为 sdk 将来可能会引入重大更改。