Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Global Constants as Default Values in Route Generation #1918

Open
srdrymn opened this issue Apr 8, 2024 · 1 comment
Open

Issue with Global Constants as Default Values in Route Generation #1918

srdrymn opened this issue Apr 8, 2024 · 1 comment

Comments

@srdrymn
Copy link

srdrymn commented Apr 8, 2024

Description

When using global constants as default values in constructors annotated with @RoutePage(), the generated route code does not include import statements for those constants, leading to unresolved references.

Steps to Reproduce

  1. Define a global constant in a separate file, for example, constants.dart:
const int appMaxWidth = 600;
  1. Import this constant in a file where a page class is defined and annotate the page with @RoutePage(), using the global constant as a default value for a parameter:
import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'constants.dart'; // Import the file with the global constant

@RoutePage()
class MyPage extends StatefulWidget {
  const MyPage({
    Key? key,
    this.maxWidth = appMaxWidth, // Use the global constant as a default value
  }) : super(key: key);

  final int maxWidth;

  @override
  _MyPageState createState() => _MyPageState();
}
  1. Run the code generation command for auto_route.

  2. Observe that the generated route code for MyPage does not include an import statement for constants.dart, resulting in an unresolved reference to appMaxWidth.

Expected Behavior

The generated route code should include all necessary import statements to resolve any references to global constants used as default values in route constructors.

Actual Behavior

The generated route code lacks import statements for external files defining global constants, leading to unresolved references.

Environment

Flutter version: 3.19.5
Dart version: 3.3.3
auto_route version: 8.0.3
auto_route_generator version: 8.0.0

@Milad-Akarie
Copy link
Owner

Hey @srdrymn yes, I'm aware of this behavior, I should resolve the alias instead of the actual unit, will try to ship a fix with the next build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants