Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter auto_route delegate and defaultRouteParser functions not exists

I have generated routing using the auth_route (5.0.1) package in my project:

import 'package:auto_route/annotations.dart';
...
part 'app_router.gr.dart';

@MaterialAutoRouter(
  replaceInRouteName: 'Page,Route',
  routes: <AutoRoute>[
    AutoRoute(page: AuthPage, initial: true),
    AutoRoute(page: TutorialPage),
    AutoRoute(page: LoginPage),
    AutoRoute(page: SmsVerificationPage),
  ],
)
class AppRouter extends _$AppRouter {}

The part-of file app_router.gr.dart generated successfully.

The problem is that the AppRouter class was not generated with the delegate() and defaultRouteParser() functions.

enter image description here

What is the problem? Anyone else is also facing the same issue?

Update

It seems that everything works just fine when the AppRouter is generated without a part-of file.

According to the official Setup, you can generate the file as part-of or not.

Apparently there is a sever difference between the two generated files:

enter image description here

I have opened an issue to auth_route on Github. Feel free to follow and contribute!

like image 250
genericUser Avatar asked Oct 19 '25 15:10

genericUser


1 Answers

i had same problem (flutter version 3.3.4 and auto_route v 5.0.1). my problem solved by importing auto_route to app_router.dart file (not generated file):

import 'package:auto_route/auto_route.dart';

app_router.dart file:

import 'package:auto_route/annotations.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';


part 'app_router.gr.dart';

@MaterialAutoRouter(
  replaceInRouteName: 'Screen,Route',
  routes: <AutoRoute>[
     ...
  ],
)
// extend the generated private router
class AppRouter extends _$AppRouter{}
like image 78
mhKarami Avatar answered Oct 21 '25 05:10

mhKarami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!