直到两天前,应用程序还正常运行。当我昨天再次尝试运行它时,没有做任何更改,我得到了以下错误:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building Builder(dirty):
The getter 'key' was called on null.
Receiver: null
Tried calling: key
The relevant error-causing widget was:
MaterialApp file:///C:/Users/jakel/Documents/GitHub/app_inspecciones/lib/main.dart:19:5
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 ExtendedNavigator.builder.<anonymous closure> (package:auto_route/src/extended_navigator.dart:37:36)
#2 _MaterialAppState._materialBuilder.<anonymous closure> (package:flutter/src/material/app.dart:756:39)
#3 Builder.build (package:flutter/src/widgets/basic.dart:7555:48)
#4 StatelessElement.build (package:flutter/src/widgets/framework.dart:4569:28)
#5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15)
#6 Element.rebuild (package:flutter/src/widgets/framework.dart:4189:5)
#7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4474:5)
#8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4469:5)
... Normal element mounting (258 frames)
#266 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
#267 Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18)
#268 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1182:16)
#269 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1153:5)
#270 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1095:18)
#271 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2647:19)
#272 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1094:13)
#273 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:934:7)
#274 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:915:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════════════════════════
错误在main.dart 中
Future main() async {
Provider.debugCheckInvalidValueType = null;
WidgetsFlutterBinding.ensureInitialized();
await configureDependencies();
final navigatorKey = GlobalKey<NavigatorState>();
await FlutterDownloader.initialize();
runApp(
MaterialApp(
builder: ExtendedNavigator.builder(
observers: [ClearFocusOnPop()],
navigatorKey: navigatorKey,
router: AutoRouter(),
builder: (context, extendedNav) => GestureDetector(
onTap: () async {
// esto quita el foco (y esconde el teclado) al hacer tap
// en cualquier lugar no-interactivo de la pantalla https://flutterigniter.com/dismiss-keyboard-form-lose-focus/
final currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus &&
currentFocus.focusedChild != null) {
currentFocus.focusedChild.unfocus();
}
},
child: Theme(
data: customTheme,
child: BlocProvider(
create: (context) =>
getIt<AuthBloc>()..add(const AuthEvent.startingApp()),
child: AuthListener(
navigatorKey: navigatorKey,
child: extendedNav,
),
),
),
),
), //InspeccionScreen(),
),
);
}
这是我在pubspec.yaml文件中的依赖项
dependencies:
flutter:
sdk: flutter
auto_route: ^0.6.9
collection: ^1.14.13
cupertino_icons: ^0.1.3
dartz: ^0.9.2
data_connection_checker: ^0.3.4
dropdown_search: ^0.4.8
enum_to_string: ^1.0.14
flutter_archive: ^2.0.1
flutter_bloc: ^6.1.1
flutter_downloader: ^1.5.2
freezed_annotation: ^0.12.0
get_it: ^5.0.1
image_picker: ^0.6.7+15
injectable: ^1.0.5
intl: ^0.16.1
json_annotation: ^3.1.1
kt_dart: ^0.8.0
moor: ^3.3.1
moor_db_viewer: ^2.0.3
multi_select_flutter: ^3.1.6
rflutter_alert: ^1.1.0
open_file: ^3.0.3
path: ^1.7.0
path_provider: ^1.6.18
pdf: ^1.13.0
provider: ^4.3.2+2
reactive_forms: ^7.6.2
share: ^0.6.5+4
shared_preferences: ^0.5.12+4
sqlite3_flutter_libs: ^0.3.0
timeline_tile: ^1.0.0
checkbox_formfield: ^0.1.0+3
dev_dependencies:
flutter_test:
sdk: flutter
auto_route_generator: ^0.6.10
build_runner: ^1.10.9
flutter_launcher_icons: ^0.8.1
freezed: ^0.12.6
injectable_generator: ^1.0.6
json_serializable: ^3.5.1
lint: ^1.3.0
moor_generator: ^3.3.1
但我不明白为什么它以前有效,现在却无效。
我已经试过在网上查找信息,但没有找到任何信息。我不知道会发生什么。也许是对2.0.2版的颤振更新
有人能帮我吗?
尝试使用最新版本的auto_route。
ExtendedNavigator.builder
现在已弃用。使用材料应用程序的routeDelegate属性。
final _appRouter = AppRouter()
...
Widget build(BuildContext context){
return MaterialApp.router(
routerDelegate: _appRouter.delegate(...initialConfig),
routeInformationParser: _appRouter.defaultRouteParser(),
),
}
跟进此线程,https://github.com/Milad-Akarie/auto_route_library/issues/378
临时解决方案是在materialapp窗口小部件中向home属性添加onGenerateRoute或伪窗口小部件