【发布时间】:2021-12-26 16:49:02
【问题描述】:
我正在尝试在我的颤振项目中使用 auto_route,但我在设置它时遇到了一些问题。 我已按照auto_route_pub 的设置指南和 youtube 上的其他指南进行操作,但由于某种原因它无法编译。
我的 router.dart 看起来像
import 'package:auto_route/annotations.dart';
import 'package:universe_ddd/presentation/authentication/authentication_screen.dart';
import 'package:universe_ddd/presentation/main_flow/main_flow_screen.dart';
import 'package:universe_ddd/presentation/splash/splash_screen.dart';
@MaterialAutoRouter(replaceInRouteName: 'Page,Route', routes: [
AutoRoute(
initial: true,
path: '/',
page: SplashScreen,
children: [RedirectRoute(path: '*', redirectTo: '')],
),
AutoRoute(
path: '/authentication',
page: AuthenticationScreen,
children: [RedirectRoute(path: '*', redirectTo: '')],
),
AutoRoute(
path: '/mainFlow',
page: MainFlowScreen,
children: [RedirectRoute(path: '*', redirectTo: '')],
),
RedirectRoute(path: '*', redirectTo: '/authentication')
])
class $AppRouter {}
生成的文件:
import 'package:auto_route/auto_route.dart' as _i4;
import 'package:flutter/material.dart' as _i5;
import '../authentication/authentication_screen.dart' as _i2;
import '../main_flow/main_flow_screen.dart' as _i3;
import '../splash/splash_screen.dart' as _i1;
class AppRouter extends _i4.RootStackRouter {
AppRouter([_i5.GlobalKey<_i5.NavigatorState>? navigatorKey])
: super(navigatorKey);
@override
final Map<String, _i4.PageFactory> pagesMap = {
SplashScreen.name: (routeData) {
return _i4.MaterialPageX<dynamic>(
routeData: routeData, child: const _i1.SplashScreen());
},
AuthenticationScreen.name: (routeData) {
return _i4.MaterialPageX<dynamic>(
routeData: routeData, child: const _i2.AuthenticationScreen());
},
MainFlowScreen.name: (routeData) {
return _i4.MaterialPageX<dynamic>(
routeData: routeData, child: const _i3.MainFlowScreen());
}
};
@override
List<_i4.RouteConfig> get routes => [
_i4.RouteConfig(SplashScreen.name, path: '/', children: [
_i4.RouteConfig('*#redirect',
path: '*',
parent: SplashScreen.name,
redirectTo: '',
fullMatch: true)
]),
_i4.RouteConfig(AuthenticationScreen.name,
path: '/authentication',
children: [
_i4.RouteConfig('*#redirect',
path: '*',
parent: AuthenticationScreen.name,
redirectTo: '',
fullMatch: true)
]),
_i4.RouteConfig(MainFlowScreen.name, path: '/mainFlow', children: [
_i4.RouteConfig('*#redirect',
path: '*',
parent: MainFlowScreen.name,
redirectTo: '',
fullMatch: true)
]),
_i4.RouteConfig('*#redirect',
path: '*', redirectTo: '/authentication', fullMatch: true)
];
}
/// generated route for
/// [_i1.SplashScreen]
class SplashScreen extends _i4.PageRouteInfo<void> {
const SplashScreen({List<_i4.PageRouteInfo>? children})
: super(SplashScreen.name, path: '/', initialChildren: children);
static const String name = 'SplashScreen';
}
/// generated route for
/// [_i2.AuthenticationScreen]
class AuthenticationScreen extends _i4.PageRouteInfo<void> {
const AuthenticationScreen({List<_i4.PageRouteInfo>? children})
: super(AuthenticationScreen.name,
path: '/authentication', initialChildren: children);
static const String name = 'AuthenticationScreen';
}
/// generated route for
/// [_i3.MainFlowScreen]
class MainFlowScreen extends _i4.PageRouteInfo<void> {
const MainFlowScreen({List<_i4.PageRouteInfo>? children})
: super(MainFlowScreen.name,
path: '/mainFlow', initialChildren: children);
static const String name = 'MainFlowScreen';
}
AppRouter 在 AppWidget 中启动,如下所示:
import 'package:universe_ddd/presentation/routes/router.gr.dart';
import '../../application/auth/auth_bloc.dart';
import '../../injection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class AppWidget extends StatelessWidget {
AppWidget({Key? key}) : super(key: key);
final _appRouter = AppRouter();
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => getIt<AuthBloc>()
..add(
const AuthEvent.authCheckRequested(),
),
)
],
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
title: 'UniVerse',
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(),
),
);
}
}
当我尝试编译应用程序时,出现以下错误:
../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/auto_route-3.2.0/lib/src/router/provider/auto_route_information_provider.dart:30:17:
Error: Type 'RouteInformationReportingType' not found.
{required RouteInformationReportingType type}) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/auto_route-3.2.0/lib/src/router/provider/auto_route_information_provider.dart:29:8:
Error: The method 'AutoRouteInformationProvider.routerReportsNewRouteInformation' doesn't have the named parameter 'isNavigation' of overridden method 'RouteInformationProvider.routerReportsNewRouteInformation'.
void routerReportsNewRouteInformation(RouteInformation routeInformation,
^
../../../../flutter/packages/flutter/lib/src/widgets/router.dart:1340:8:
Context: This is the overridden method ('routerReportsNewRouteInformation').
void routerReportsNewRouteInformation(RouteInformation routeInformation, {bool isNavigation = true}) {}
^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/auto_route-3.2.0/lib/src/router/controller/auto_router_delegate.dart:30:17:
Error: Getter not found: 'RouteInformationReportingType'.
type: RouteInformationReportingType.navigate,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/auto_route-3.2.0/lib/src/router/controller/auto_router_delegate.dart:30:11:
Error: No named parameter with the name 'type'.
* Get more help at https://help.gradle.org
BUILD FAILED in 27s
我的其余依赖项:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
freezed_annotation: ^1.1.0
dartz: ^0.10.1
firebase_core: ^1.10.6
firebase_auth: ^3.3.4
flutter_bloc: ^8.0.0
injectable: ^1.5.0
get_it: ^7.2.0
cloud_firestore: ^3.1.5
auto_route: ^3.2.0
dev_dependencies:
flutter_test:
sdk: flutter
injectable_generator: ^1.5.2
flutter_lints: ^1.0.0
build_runner: ^2.1.7
mockito: ^5.0.17
freezed: ^1.1.0
auto_route_generator: ^3.2.0
我正在使用颤振 2.5.3,飞镖 2.14.4,auto_route:^3.2.0,auto_route_generator:^3.2.0。 我在较早的页面上找不到任何这样的问题,所以我可能在做一些愚蠢的事情,但无法弄清楚=)如果有人知道出了什么问题或看到了类似的问题,我会很感激任何建议. 谢谢!
【问题讨论】:
标签: android flutter dart flutter-dependencies dart-pub