You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Define a global constant in a separate file, for example, constants.dart:
constint appMaxWidth =600;
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()
classMyPageextendsStatefulWidget {
constMyPage({
Key? key,
this.maxWidth = appMaxWidth, // Use the global constant as a default value
}) :super(key: key);
finalint maxWidth;
@override_MyPageStatecreateState() =>_MyPageState();
}
Run the code generation command for auto_route.
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.
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
constants.dart
:Run the code generation command for auto_route.
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
The text was updated successfully, but these errors were encountered: