Open tattuu opened 1 year ago
The errors you're seeing aren't produced by Freezed by Dart itself.
Freezed is unlikely to be at fault here. Rather there's something in your code/environment which causes this.
Without a reproducible example, there's nothing I can do to help.
Thank you for your message. It seems unlikely that Freezed is the cause.
In sending the issue, I created a new flutter project and tried to reproduce the issue, and got the same error. So, if it is not due to freezed, it is most likely a bug in flutter itself.
Just to be sure, I will share the details of my environment where this error occurred.
dev_dependencies:
build_runner: ^2.4.4
freezed: ^2.3.4
flutter pub get
Copy and paste the following code into your file
import 'package:freezed_annotation/freezed_annotation.dart';
part 'temp_state.freezed.dart';
@freezed
class TempState with _$TempState {
const factory TempState({
// one line
@Default(<Map<String, dynamic>>[]) List<Map<String, dynamic>> xxx,
}) = _TempState;
}
flutter packages pub run build_runner build --delete-conflicting-outputs
Sorry to take up your time. This is a very puzzling error, and if it is not likely to be caused by freezed, I would like to throw an issue to flutter project itself.
Tested with freezed: ^2.5.3
. This is a work-around:
import 'package:freezed_annotation/freezed_annotation.dart';
part 'temp_state.freezed.dart';
const map = <Map<String, dynamic>>[]; // <-------- Define the default value
@freezed
class TempState with _$TempState {
const factory TempState({
@Default(map) List<Map<String, dynamic>> xxx, // <------- One single line of code
}) = _TempState;
}
and in the generated file temp_state.freezed.dart
:
...
/// @nodoc
mixin _$TempState {
List<Map<String, dynamic>> get xxx => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$TempStateCopyWith<TempState> get copyWith =>
throw _privateConstructorUsedError;
}
...
If the annotation is replaced with: @Default(<Map<String, dynamic>>[])
the generated file temp_state.freezed.dart
becomes:
...
/// @nodoc
mixin _$TempState {
Map<String, dynamic>>[]) List<Map<String, dynamic>> get xxx => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$TempStateCopyWith<TempState> get copyWith => throw _privateConstructorUsedError;
}
...
So to me this looks like an error with the source code generator where it renders
Map<String, dynamic>>[]) List<Map<String, dynamic>>
instead of the type List<Map<String, dynamic>>
throughout the generated file.
Describe the bug If you create a value of type
List<Map<String, dynamic>>
in State, and write it as shown in the attached image 1, there will be no errors when you executeflutter pub run build_runner build
in two lines. However, if you executeflutter pub run build_runner build
in one line, you will get the error message:"The name 'Map' isn't a type, so it can't be used as a type argument. Try correcting the name to an existing type or defining a type named 'Map'."
In this particular type, an error occurs only when it is written in a single line.
To Reproduce
no error
error
Expected behavior I believe it is desirable for the code to not produce any errors, regardless of whether it is written in one line or two lines.
As this is my first issue to submit to the this project, I apologize if I have provided any incorrect information. I would appreciate it if you could reply whenever you have time.