英文:
Undefined name AdaptiveAutoRouter used as an annotation
问题
I keep on getting this error (Android Studio).
lib/routes/router.dart
:
import 'package:auto_route/auto_route.dart';
import 'package:salomon_routing_tutorial/home_page.dart';
...
@AdaptiveAutoRouter(
replaceInRouteName: 'Page,Route',
...
pubspec.yaml
:
name: salomon_routing_tutorial
description: Flutter底部导航与嵌套路由教程。
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.17.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
auto_route: ^6.0.5
salomon_bottom_bar: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.4
auto_route_generator: ^6.0.3
build_runner: ^2.1.2
analyzer: ^5.10.0
flutter:
uses-material-design: true
A typo should be out of the question, the name in question is copied from a working project. What could it be?
英文:
I keep on getting this error (Android Studio).
lib/routes/router.dart
:
import 'package:auto_route/auto_route.dart';
import 'package:salomon_routing_tutorial/home_page.dart';
...
@AdaptiveAutoRouter(
replaceInRouteName: 'Page,Route',
...
pubspec.yaml
:
name: salomon_routing_tutorial
description: Flutter Bottom Navigation with Nested Routing Tutorial.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.17.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
auto_route: ^6.0.5
salomon_bottom_bar: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.4
auto_route_generator: ^6.0.3
build_runner: ^2.1.2
analyzer: ^5.10.0
flutter:
uses-material-design: true
A typo should be out of the question, the name in question is copied from a working project. What could it be?
答案1
得分: 2
- 删除您的 router.dart 和 router.gr.dart(如果已创建)文件。
- 创建一个名为 app_router.dart 的文件,并复制以下代码。
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
part 'app_router.gr.dart';
@AutoRouterConfig(replaceInRouteName: 'Page,Route')
class AppRouter extends _$AppRouter {
@override
RouteType get defaultRouteType => const RouteType.adaptive(); //.cupertino, .adaptive ..etc
@override
final List<AutoRoute> routes = [
// 在此添加路由
];
}
保存并运行 build_runner
英文:
Try this..
-
Delete your router.dart and router.gr.dart (if created) file
-
Create a file app_router.dart and copy below code.
import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; part 'app_router.gr.dart'; @AutoRouterConfig(replaceInRouteName: 'Page,Route') class AppRouter extends _$AppRouter { @override RouteType get defaultRouteType => const RouteType.adaptive(); //.cupertino, .adaptive ..etc @override final List<AutoRoute> routes = [ //routes here ]; }
save and run build_runner
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论