0

The code below doesn't work instead it shows what i want to achieve.

As you can see I want to set text to use the color that color is set to.

class AppThemeModal{

    AppThemeModal({required this.color});

    Color color;

    TextStyle text = TextStyle(color: color);
}

1 Answers1

1

You can't access the instance variable before the object is created, but you can reference the parameter in the initializer list:

class AppThemeModal{
  AppThemeModal({required this.color})
      : text = TextStyle(color: color);

  final Color color;
  final TextStyle text;
}
lrn
  • 64,680
  • 7
  • 105
  • 121