flutter 用作注解的未定义名称AdaptiveAutoRouter

cbwuti44  于 2023-04-07  发布在  Flutter
关注(0)|答案(1)|浏览(157)

我一直得到这个错误(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

一个错字应该是不可能的,有问题的名字是从一个工作项目中复制的。它会是什么呢?

6gpjuf90

6gpjuf901#

试试这个。
1.删除router.dart和router.gr.dart(如果已创建)文件
1.创建一个文件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 = [
  //routes here
 ];
}

保存并运行build_runner

相关问题