import 'package:flutter/material.dart';

class DefaultButton extends StatefulWidget {
  //点击回调
  final GestureTapCallback onPressed;
  final String text;
  final EdgeInsetsGeometry margin;
  final double width;
  final double height;
  final double? fontSize;
  final Color backColor;
  final Color color;
  final double? radius;

  EdgeInsetsGeometry marginDefault =
      const EdgeInsets.fromLTRB(0, 90.0, 0, 30); //按钮默认的margin值

  DefaultButton({
    Key? key,
    required this.onPressed,
    required this.text,
    required this.margin,
    required this.width,
    required this.height,
    this.fontSize,
    this.radius,
    required this.backColor,
    required this.color,
  }) : super(key: key);

  @override
  State createState() {
    if (margin == null) {
      return _DefaultButtonState(onPressed, text, marginDefault, width, height,
          fontSize, backColor, color, radius);
    }
    return _DefaultButtonState(onPressed, text, margin, width, height, fontSize,
        backColor, color, radius);
  }
}

class _DefaultButtonState extends State<DefaultButton> {
  //点击回调
  final GestureTapCallback onPressed;
  final String text;
  final EdgeInsetsGeometry margin;
  final double width;
  final double height;
  final double? fontSize;
  final Color backColor;
  final Color color;
  final double? radius;
  _DefaultButtonState(this.onPressed, this.text, this.margin, this.width,
      this.height, this.fontSize, this.backColor, this.color, this.radius);

  @override
  Widget build(BuildContext context) {
    Widget _SectionBtn = Container(
      margin: margin,
      child: SizedBox(
        width: width,
        height: height,
        child: RaisedButton(
          color: backColor,
          disabledColor: const Color(0xF5F6F7ff),
          disabledTextColor: const Color(0xF5F6F7ff),
          colorBrightness: Brightness.dark,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(radius ?? 5)),
          child: Text(
            text,
            style: TextStyle(
              fontSize: fontSize,
              fontWeight: FontWeight.bold,
              color: color,
            ),
          ),
          textColor: Colors.white,
          onPressed: onPressed,
        ),
      ),
    );

    return _SectionBtn;
  }
}