Newer
Older
flutterBaseApp / lib / ui / widgets / common / button / round_button_widget.dart
StephanieGitHub on 9 Feb 2021 1 KB first commit
import 'package:flutter/material.dart';

// 圆形按钮Widget
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,
  }) : super(key: key);

  final double width; // 宽
  final double height; // 高
  final EdgeInsetsGeometry margin; // 边距
  final double radius; // 圆角
  final Color bgColor; // 背景颜色
  final Color highlightColor; // 高亮颜色?未用到
  final Color splashColor; //?未用到

  final Widget child; // 子元素

  final String text; // 文字
  final TextStyle style; // 文字样式

  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(
      width: width,
      height: height,
      margin: margin,
      child: new Material(
        borderRadius: _borderRadius,
        color: _bgColor,
        child: new InkWell(
          borderRadius: _borderRadius,
          onTap: () => onPressed(),
          child: child ??
              new Center(
                child: new Text(
                  text,
                  style:
                      style ?? new TextStyle(color: Colors.white, fontSize: 16),
                ),
              ),
        ),
      ),
    );
  }
}