getResponsiveWidget method

  1. @override
Widget getResponsiveWidget(
  1. BuildContext context,
  2. ScreenType screenType,
  3. double scale
)
override

Implementation

@override
Widget getResponsiveWidget(BuildContext context, ScreenType screenType, double scale) {

    double fontSize = 0.0;
    double? newFontSize;

    TextStyle responsiveStyle = DefaultTextStyle.of(context).style;
    TextStyle defaultStyle =  DefaultTextStyle.of(context).style;
    ButtonStyle responsiveButtonStyle;

    if(responsiveStyle.fontSize != null) {
      fontSize = responsiveStyle.fontSize!;
    } else {
      fontSize = defaultStyle.fontSize!;
    }

    newFontSize = fontSize * scale;

    if(has('style')) {
      responsiveButtonStyle = get('style');
    } else {
      responsiveButtonStyle = TextButton.styleFrom(textStyle: defaultStyle);
    }

    responsiveStyle = responsiveStyle.copyWith(fontSize: newFontSize);

    responsiveButtonStyle = responsiveButtonStyle.copyWith(textStyle: ButtonStyleButton.allOrNull<TextStyle>(responsiveStyle));

    return TextButton(
      key : get('key'),
      onPressed : onPressed,
      onLongPress : onLongPress,
      onHover : onHover,
      onFocusChange : onFocusChange,
      style : responsiveButtonStyle,
      focusNode : get('focusNode'),
      autofocus : get('autofocus'),
      clipBehavior : get('clipBehavior'),
      child : child
    );
}