Undefined name AdaptiveAutoRouter used as an annotation.

huangapple go评论65阅读模式
英文:

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 &#39;package:auto_route/auto_route.dart&#39;;
import &#39;package:salomon_routing_tutorial/home_page.dart&#39;;
...
@AdaptiveAutoRouter(
  replaceInRouteName: &#39;Page,Route&#39;,
...

pubspec.yaml:

name: salomon_routing_tutorial
description: Flutter Bottom Navigation with Nested Routing Tutorial.
publish_to: &#39;none&#39;
version: 1.0.0+1
environment:
  sdk: &quot;&gt;=2.17.0 &lt;3.0.0&quot;

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

  1. 删除您的 router.dart 和 router.gr.dart(如果已创建)文件。
  2. 创建一个名为 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..

  1. Delete your router.dart and router.gr.dart (if created) file

  2. Create a file app_router.dart and copy below code.

    import &#39;package:auto_route/auto_route.dart&#39;;
    import &#39;package:flutter/material.dart&#39;;       
    part &#39;app_router.gr.dart&#39;;
    
    @AutoRouterConfig(replaceInRouteName: &#39;Page,Route&#39;)
    class AppRouter extends _$AppRouter {
    
      @override      
      RouteType get defaultRouteType =&gt; const RouteType.adaptive(); //.cupertino, .adaptive ..etc 
    
     @override
     final List&lt;AutoRoute&gt; routes = [
      //routes here
     ];
    }
    

save and run build_runner

huangapple
  • 本文由 发表于 2023年4月4日 17:22:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75927662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定