0

I've entered for the first time into Flutter on an already going on a project. This project was using the auto_route plugin already, with multiple pages.

As a task, I needed to update the version of the plugin to the last one (now 7.7.1)

I used the plugin on Android Studio suggested by them, AutoRoute-helper, to change the majority of the things.

I fixed one or two other things, but there is one I cannot fix:

AutoRoute(path: '/auth/', page: Auth.page, meta: {'name': 'Authentication'}),

In the Router file.

But I'm receiving the error: The getter 'page' isn't defined for the type 'Auth'.

Inside the page authentication.dart (imported inside router):

...
import 'package:auto_route/auto_route.dart';
...

@RoutePage()
class Auth extends StatefulWidget {
  final int? eventRedirectId;
  final VoidCallback? onAuthenticationComplete;

  const Auth({
    Key? key,
    this.onAuthenticationComplete,
    this.eventRedirectId
  }) : super(key: key);

  @override
  AuthState createState() => AuthState();
}

...

I launched the command flutter packages pub run build_runner build but still my router doesn't recognize the .name

I couldn't find any documentation or tutorial that does something different from what i did, does somebody have any idea on what could be the problem?

I tried to follow step by-step any tutorial I could find on how to create a new project with auto_route, doing the exact same things. I don't understand what i could miss, and where the name comes from, everybody just seems to add @RoutePage(), build, and then they can use the name property.

---------------------------UPDATE

The problem i had is that classes are imported not from the page directly, but from the router.gr.dart file. By default, generated classes there have the suffix Route, so my class was not Auth, but AuthRoute.

Using AuthRoute.name solved the issue.

  • In the auto_router.gr, do you find the generated class for "Auth"? – VincentDR Aug 01 '23 at 14:55
  • @VincentDR - Yes This is the class. If I switch the name to AuthRoute actually I can find the .name. I don't understand, now I see that also every other page has Route at the end of the name. But the tutorial doesn't mention writing anything in that file at first by hand, can it be that to me it didn't create because he already found it with another name? Really thank you | AuthRoute.name: (routeData) { final args = routeData.argsAs(orElse: () => const AuthRouteArgs()); return _i30.AutoRoutePage( ... – Zannabrighel Aug 01 '23 at 15:20
  • By default, it's add (or replace a part of the classname) "Route" to the generated classess. https://pub.dev/packages/auto_route#generated-routes:~:text=Add%20the%20generated%20route%20to%20your%20routes%20list – VincentDR Aug 01 '23 at 15:27
  • @VincentDR what should I do? i would like to keep this topic alive if somebody ever will encounter the same issue. Can you write down that as an answer so I can mark it as the solution? thank you – Zannabrighel Aug 01 '23 at 15:41

1 Answers1

0

By default, the package add (or replace a part of the classname) "Route" to the generated classes.

You can even specify what part of the classname to replace: https://pub.dev/packages/auto_route#generated-routes:~:text=Add%20the%20generated%20route%20to%20your%20routes%20list

VincentDR
  • 696
  • 3
  • 15