I am new to flutter. I am facing a few issues with the const constructors.
class StartOnboarding extends OnboardingEvent {
final User user;
const StartOnboarding({
this.user = const User(
id: '',
name: '',
age: 0,
gender: '',
imageUrls: [],
),
});
@override
List<Object?> get props => [user];
}
I am getting these two errors:
The default value of an optional parameter must be constant.
The constructor being called isn't a const constructor. Try removing 'const' from the constructor invocation.
On your User
constructor, you need to use const
in order use const on StartOnboarding
class StartOnboarding extends OnboardingEvent {
final User user;
const StartOnboarding({
this.user = const User(
id: '',
name: '',
age: 0,
gender: '',
imageUrls: [],
),
});
@override
List<Object?> get props => [user];
}
class User {
final String id;
final String name;
final int age;
final String gender;
final List<String> imageUrls;
const User({
required this.id,
required this.name,
required this.age,
required this.gender,
required this.imageUrls,
});
}