round_button.dart 3.35 KB
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';

class RoundButton extends StatelessWidget {
  const RoundButton(
      {Key key,
      this.width,
      this.height = 50,
      this.margin,
      this.radius,
      this.bgColor,
      this.highlightColor,
      this.splashColor,
      this.child,
      this.text,
      this.style,
      this.onPressed,
      this.image,
      this.imgWidth = 13.0,
      this.fontSize = 24,
      this.gradientStart = MyColours.color_199095,
      this.gradientEnd = MyColours.color_199095,
      this.textColor = Colors.white,
      this.borderColor = Colors.transparent,
      this.isBold = true,
      this.padding = EdgeInsets.zero,
      this.space = 6})
      : super(key: key);

  final String image;
  final double width;
  final double height;
  final double imgWidth;
  final double fontSize;
  final Color textColor;
  final bool isBold;

  /// Empty space to surround the [decoration] and [child].
  final EdgeInsetsGeometry margin;

  final double radius;
  final Color bgColor;
  final Color highlightColor;
  final Color splashColor;
  final Color gradientStart;
  final Color gradientEnd;
  final Widget child;
  final Color borderColor;
  final double space;

  final String text;
  final TextStyle style;
  final EdgeInsetsGeometry padding;

  final VoidCallback onPressed;

  @override
  Widget build(BuildContext context) {
    Color _bgColor = bgColor ?? Theme.of(context).primaryColor;
    BorderRadius _borderRadius = BorderRadius.circular(radius ?? (height / 2));
    return new Container(
        padding: padding,
        width: width,
        height: height,
        margin: margin,
        decoration: BoxDecoration(
          borderRadius: _borderRadius,
          border:
              Border.all(color: borderColor, width: ScreenUtil().setWidth(2)),
          gradient: LinearGradient(
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
            colors: [
              gradientStart,
              gradientEnd,
            ],
          ),
        ),
        child: new InkWell(
          borderRadius: _borderRadius,
          onTap: () => onPressed(),
          child: child ??
              new Center(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    !ObjectUtil.isEmptyString(image)
                        ? Padding(
                            padding: EdgeInsets.only(right: space, bottom: 3),
                            child: Image.asset(
                              image,
                              width: ScreenUtil().setWidth(imgWidth),
                            ),
                          )
                        : Text(''),
                    Text(
                      text,
                      overflow: TextOverflow.ellipsis,
                      style: style ??
                          new TextStyle(
                              color: textColor,
                              fontSize: ScreenUtil().setSp(fontSize),
                              fontWeight:
                                  isBold ? FontWeight.bold : FontWeight.normal),
                    )
                  ],
                ),
              ),
        ));
  }
}