How to make text subtitle after decimal value automated widget in Flutter

Viewed 14

This a widget copy and just give the value It will automatically convert in child widgets and divided into subtitles and titles after and before decimals in flutter

class MyText extends StatelessWidget {
const MyText(
  {Key? key,
  required this.title,
  this.titleStyle = const TextStyle(
    color: Colors.black,
    fontWeight: FontWeight.w700,
    fontSize: 15,
  ),
  this.subTitleStyle = const TextStyle(
    color: Colors.black,
    fontWeight: FontWeight.w700,
    fontSize: 12,
  ),
  this.rialStyle = const TextStyle(color: Colors.black),
  this.rial = 'ريال',
  this.isRial=true
  })
  : super(key: key);

These are the passing values and totally optional

final String rial;
final String title;
final TextStyle titleStyle;
final TextStyle subTitleStyle;
final TextStyle rialStyle;
final bool isRial;`

It takes a value which merge in to _value

@override
Widget build(BuildContext context) {
final _value = double.parse(title).toStringAsFixed(2);
return Row(
  // ignore: prefer_const_literals_to_create_immutables
  children: [
    RichText(
      text: TextSpan(
        text: _value.split('.')[0],
        style: titleStyle,
        children: <TextSpan>[
          // TextSpan(text: title.split('.')[0], style: titleStyle),
          TextSpan(
            text: '.${_value.split('.')[1].substring(0, 2)}',
            style: subTitleStyle,
          ),
        ],
      ),
    ),
  ],
 );
}
}

Enjoy your life

0 Answers
Related