I'm working on a project using bloc pattern and I have a problem with the initial state of my home page state class. Here's the code:
class HomeState extends Equatable {
const HomeState({
this.screenTittle = LocaleKeys.mainMenu.tr(),
this.screenIndex = 0,
this.showBurguerMenu = false,
});
final String screenTittle;
final int screenIndex;
final bool showBurguerMenu;
@override
List<Object?> get props => [screenTittle, screenIndex, showBurguerMenu];
HomeState copyWith({
String? screenTittle,
int? screenIndex,
bool? showBurguerMenu,
}) {
return HomeState(
screenTittle: screenTittle ?? this.screenTittle,
screenIndex: screenIndex ?? this.screenIndex,
showBurguerMenu: showBurguerMenu ?? this.showBurguerMenu,
);
}
}
this is the state class and the problem is with
this.screenTiitle = LocalKeys.mainMenu.tr()
because im using localKeys to translate a text and i'm getting this error
The default value of an optional parameter must be constant.
because the .tr() makes the translation converts the localKeys in not constant and I need to set a text that can be translated in the initial state.
I tried removing the const of the constructor , also the final of the variable and defining the initial state in the variable, I also tried to make a method and called it from the constructor but I always got the same error https://i.stack.imgur.com/O94Ao.png
Is there a way to make the builder accept and non constant value?