-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Closed
flutter/packages
#3415Closed
Copy link
Labels
found in release: 3.7Found to occur in 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Steps to Reproduce
- Execute
flutter pub run build_runner build --delete-conflicting-outputson the code sample (see "Code sample" section below) - Notice that the enum map is not generated and leads to errors
Expected results:
The enum map should be generated when an enum is used in an Iterable
Actual results:
The enum map is not generated when an enum is used in an Iterable
Code sample
You can also checkout https://github.com/ValentinVignal/flutter_app_stable/tree/go-router-builder/enum-in-iterables
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
part 'main.g.dart';
enum MyEnum {
value0,
value1,
}
@TypedGoRoute<MyRoute>(path: '/')
class MyRoute extends GoRouteData {
const MyRoute({
this.iterable,
});
final List<MyEnum>? iterable;
@override
Widget build(BuildContext context, GoRouterState state) =>
const Placeholder();
}Generates:
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'main.dart';
// **************************************************************************
// GoRouterGenerator
// **************************************************************************
List<GoRoute> get $appRoutes => [
$myRoute,
];
GoRoute get $myRoute => GoRouteData.$route(
path: '/',
factory: $MyRouteExtension._fromState,
);
extension $MyRouteExtension on MyRoute {
static MyRoute _fromState(GoRouterState state) => MyRoute(
iterable: state.queryParametersAll['iterable'] // <- The argument type 'List<dynamic>?' can't be assigned to the parameter type 'List<MyEnum>?'.dart[argument_type_not_assignable](https://dart.dev/diagnostics/argument_type_not_assignable)
?.map(_$MyEnumEnumMap._$fromName) // <- The argument type 'List<dynamic>?' can't be assigned to the parameter type 'List<MyEnum>?'.dart[argument_type_not_assignable](https://dart.dev/diagnostics/argument_type_not_assignable)
.toList(),
);
String get location => GoRouteData.$location(
'/',
queryParams: {
if (iterable != null)
'iterable': iterable?.map((e) => _$MyEnumEnumMap[e]).toList(), // <- Undefined name '_$MyEnumEnumMap'.
},
);
void go(BuildContext context) => context.go(location);
void push(BuildContext context) => context.push(location);
void pushReplacement(BuildContext context) =>
context.pushReplacement(location);
}
extension<T extends Enum> on Map<T, String> {
T _$fromName(String value) => // <- The declaration '_$fromName' isn't referenced. Try removing the declaration of '_$fromName'.dart[unused_element](https://dart.dev/diagnostics/unused_element)
entries.singleWhere((element) => element.value == value).key;
}Logs
Analyzing flutter_app_stable...
error • The argument type 'List<dynamic>?' can't be assigned to the parameter type 'List<MyEnum>?' • lib/main.g.dart:20:19 • argument_type_not_assignable
error • Undefined name '_$MyEnumEnumMap' • lib/main.g.dart:21:19 • undefined_identifier
error • Undefined name '_$MyEnumEnumMap' • lib/main.g.dart:29:46 • undefined_identifier
info • The declaration '_$fromName' isn't referenced • lib/main.g.dart:42:5 • unused_element
4 issues found. (ran in 2.7s)
[✓] Flutter (Channel stable, 3.3.10, on macOS 11.6.8 20G730 darwin-x64, locale en-GB)
• Flutter version 3.3.10 on channel stable at /Users/valentin/flutter/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 135454af32 (3 months ago), 2022-12-15 07:36:55 -0800
• Engine revision 3316dd8728
• Dart version 2.18.6
• DevTools version 2.15.0
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /usr/local/Caskroom/android-sdk/4333796
• Platform android-33, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 13C100
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
[✓] VS Code (version 1.76.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.60.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 11.6.8 20G730 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.177
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Metadata
Metadata
Assignees
Labels
found in release: 3.7Found to occur in 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_router_builderThe go_router_builder packageThe go_router_builder packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version