import 'package:flutter/material.dart';
import '../data/constants.dart' show Constants, AppColors;

class FullWidthButton extends StatelessWidget {
  static const Hor_Padding = 5.0;
  static const Ver_Padding = 10.0;

  final String title;
  final bool showDivider;
  final VoidCallback onPressed;
  final String description;
  final Color descriptionColor;
  final bool showRightIcon;

  final Widget extendWidget;

  const FullWidthButton(
      {@required this.title,
      this.description = '',
      @required this.onPressed,
      this.descriptionColor,
      this.showRightIcon: true,
      this.showDivider: false,
      this.extendWidget
      })
      : assert(title != null),
        assert(onPressed != null);

  @override
  Widget build(BuildContext context) {
    final pureButton = Row(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        SizedBox(width: Hor_Padding),
        Expanded(
          child: Text(
            title,
            textScaleFactor: 1.0,
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.normal
            ),
          ),
        ),
        extendWidget!=null?extendWidget: Text(
          description,
          textScaleFactor: 1.0,
          textAlign: TextAlign.end,
          style: TextStyle(
              fontSize: 12,
              fontWeight: FontWeight.normal,
              color: descriptionColor == null
                  ? const Color(0xFF818181)
                  : descriptionColor),
        ),
        showRightIcon
            ? Padding(
                padding: EdgeInsets.only(bottom: 1.5),
                child: Icon(
                  IconData(0xe63c, fontFamily: 'iconfont'),
                  size: 20.0,
                  color: Color(AppColors.TabIconNormal),
                ))
            : Padding(padding: EdgeInsets.only(right: 7)),
      ],
    );

    final borderButton = Container(
      decoration: BoxDecoration(
        border: Border(
          bottom: Constants.GreyBorderSide,
        ),
      ),
      padding: EdgeInsets.only(
        bottom: Ver_Padding,
      ),
      child: pureButton,
    );

    return FlatButton(
      onPressed: () {
        this.onPressed();
      },
      padding: EdgeInsets.only(
        left: Hor_Padding,
        right: Hor_Padding,
        top: Ver_Padding,
        bottom: showDivider ? 0.0 : Ver_Padding,
      ),
      color: Colors.white,
      child: showDivider ? borderButton : pureButton,
    );
  }
}
