textOnColor static method

Widget textOnColor(
  1. BuildContext context, {
  2. required String text,
  3. bool expanded = false,
  4. TextStyle? style,
  5. Color? backgroundColor,
  6. TextAlign? textAlign,
  7. double horizontalGap = 10,
  8. double verticalGap = 10,
  9. Color textColor = Colors.black87,
})

Creates a text widget on a colored rounded container background.

Parameters:

  • context: The build context to access theme data
  • text: The text to display
  • expanded: Whether to expand the widget horizontally. Defaults to false
  • style: Optional text style
  • backgroundColor: Optional background color. Defaults to grey
  • textAlign: Optional text alignment
  • horizontalGap: Horizontal padding. Defaults to 10
  • verticalGap: Vertical padding. Defaults to 10
  • textColor: Text color. Defaults to black87

Implementation

static Widget textOnColor(BuildContext context,
    {required String text,
    bool expanded = false,
    TextStyle? style,
    Color? backgroundColor,
    TextAlign? textAlign,
    double horizontalGap = 10,
    double verticalGap = 10,
    Color textColor = Colors.black87}) {
  Widget c = Container(
    decoration: BoxDecoration(
        color: backgroundColor ?? Colors.grey.shade200,
        borderRadius: BorderRadius.circular(6)),
    padding: EdgeInsets.symmetric(
        horizontal: horizontalGap, vertical: verticalGap),
    child: Text(
      text,
      style: style ??
          Theme.of(context).textTheme.titleMedium!.copyWith(color: textColor),
      textAlign: textAlign,
    ),
  );

  if (expanded) {
    return Row(children: [c.expanded()]);
  } else {
    return c;
  }
}