Home > Software design >  flutter call shadow widget of textstyle from class
flutter call shadow widget of textstyle from class

Time:10-04

Im very new to flutter, I want to make the code as much as less, so instead of using shadow widget every time, i want to call it but I don't know how to make the shadows widget as fixed variable

    class ShadowTextStyle extends TextStyle {
      final Color color;
      final FontWeight fontWeight;
      final double size;
      final List<Shadow>? shadows;
      const ShadowTextStyle({
        required this.color,
        required this.fontWeight,
        this.size = 14,
        this.shadows =//how to do it here,
        ,
    
      }): super(
            color: color,
            fontWeight: fontWeight,
            fontSize: size,
            shadows: shadows,
          );
    }

this is the shadow parameters, I want to make it fix

      shadows: <Shadow>[
        Shadow(
          offset: Offset(1.0, 0.0),
          blurRadius: 5.0,
          color: Color.fromARGB(255, 0, 0, 0),
        ),
      ],

CodePudding user response:

I'm not sure if I get the question right, but you can assign your customized shadow to a variable, I always have a style.dart file where I save my customized styles.

Shadow myShadow = Shadow(
  offset: Offset(1.0, 0.0),
  blurRadius: 5.0,
  color: Color.fromARGB(255, 0, 0, 0),
);

CodePudding user response:

I found it. This is what I meant:

const ShadowFile = <Shadow>[
  Shadow(
    offset: Offset(1.0, 0.0),
    blurRadius: 5.0,
    color: Color.fromARGB(255, 0, 0, 0),
  )
];

class ShadowTextStyle extends TextStyle {
  final Color color;
  final FontWeight fontWeight;
  final double size;
  const ShadowTextStyle({
    required this.color,
    required this.fontWeight,
    this.size = 14,
    shadows: ShadowFile,
  }) : super(
          color: color,
          fontWeight: fontWeight,
          fontSize: size,
         shadows: ShadowFile,
        );
}
  • Related