import 'package:flutter/material.dart'; class IconText extends StatelessWidget { final String leftImage; final String rightImage; final IconData leftIcon; final IconData rightIcon; final String text; final TextStyle textStyle; final double iconSize; final Color iconColor; final CrossAxisAlignment textAxisAlignment; final bool isMax; IconText(this.text, {this.leftIcon, this.rightIcon, this.leftImage, this.rightImage, this.isMax = false, this.iconSize = 16, this.textAxisAlignment = CrossAxisAlignment.center, this.iconColor = Colors.black, this.textStyle}); @override Widget build(BuildContext context) { var widgets = []; if (leftIcon != null || (leftImage != null && leftImage != "")) { if (leftIcon != null) { widgets.add( Padding( padding: EdgeInsets.all(2), child: Icon( leftIcon, size: iconSize, color: iconColor, ), ), ); } else if (leftImage != null && leftImage != "") { widgets.add(Padding( padding: EdgeInsets.all(2), child: Image.asset( leftImage, width: iconSize, height: iconSize, ), )); } } widgets.add(isMax ? Expanded( child: Text( text, textAlign: TextAlign.start, style: textStyle, ), flex: 1, ) : Text( text, textAlign: TextAlign.center, style: textStyle, )); if (rightIcon != null || rightImage != null && rightImage != "") { if (rightIcon != null) { widgets.add( Padding( padding: EdgeInsets.all(2), child: Icon( rightIcon, size: iconSize, color: iconColor, ), ), ); } else if (rightImage != null && rightImage != "") { widgets.add( Padding( padding: EdgeInsets.all(2), child: Image.asset( rightImage, width: iconSize, height: iconSize, ), ), ); } } return Container( child: Row( mainAxisAlignment: isMax ? MainAxisAlignment.center : MainAxisAlignment.start, crossAxisAlignment: textAxisAlignment, mainAxisSize: MainAxisSize.min, children: widgets, ), ); } }