textOnColor static method
Creates a text widget on a colored rounded container background.
Parameters:
context: The build context to access theme datatext: The text to displayexpanded: Whether to expand the widget horizontally. Defaults to falsestyle: Optional text stylebackgroundColor: Optional background color. Defaults to greytextAlign: Optional text alignmenthorizontalGap: Horizontal padding. Defaults to 10verticalGap: Vertical padding. Defaults to 10textColor: 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;
}
}