
import 'package:flutter/material.dart';

class ShowPrice extends StatelessWidget {
  final double price;
  final double regularPrice;
  final double largeFontSize;
  final double smallFontSize;
  final String currencySign;
  final Color color;
  final FontWeight fontWeight;

  ShowPrice(this.price,
      {
        this.regularPrice,
        this.largeFontSize = 20,
        this.smallFontSize = 12,
        this.currencySign,
        this.color = Colors.red,
        this.fontWeight = FontWeight.normal,
      });

  @override
  Widget build(BuildContext context) {
    String priceString = price.toStringAsFixed(2);
    var arr = priceString.split('.');
    String num1 = arr[0];
    String num2 = arr[1];

    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          currencySign != null ?
              Container(
                padding: EdgeInsets.only(top: largeFontSize / 10.0),
                child: Text(
                  currencySign,
                  style: TextStyle(
                    fontSize: smallFontSize,
                    color: color,
                    fontWeight: fontWeight,
                  ),
                ),
              ) : SizedBox.shrink(),
          Container(
            child: Text(
              num1,
              style: TextStyle(
                color: color,
                fontSize: largeFontSize,
                fontWeight: fontWeight,
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.only(top: largeFontSize / 10.0),
            child: Text(
              '.$num2',
              style: TextStyle(
                color: color,
                fontSize: smallFontSize,
                fontWeight: fontWeight,
              ),
            ),
          ),
          regularPrice == null || price.round() >= regularPrice.round() ?
          SizedBox.shrink() :
          Container(
            padding: EdgeInsets.only(top: largeFontSize / 2),
            child: Text(
              regularPrice.toStringAsFixed(0),
              style: TextStyle(
                color: Colors.black38,
                fontSize: smallFontSize,
                decoration: TextDecoration.lineThrough,
              ),
            ),
          ),
        ],
      ),
    );
  }

}