common_button_flat_new.dart 7.37 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';

class CommonButtonFlatNew extends StatelessWidget {
  final VoidCallback onPress;
  final String content;
  // final double width;
  final double height;
  final double fontSize;
  final int state; //-1 不可用 0 默认 1 选中
  final FontWeight fontWeight;
  final bool left;
  final bool right;
  final EdgeInsets padding;
  CommonButtonFlatNew(
      {this.onPress,
      this.content,
      this.state = 0,
      // this.width ,
      this.height = 50,
      this.fontSize = 18,
      this.fontWeight = FontWeight.normal,
      this.left = true,
      this.right = true,
      this.padding = EdgeInsets.zero});

  @override
  Widget build(BuildContext context) {
    BoxDecoration boxDecoration;
    Color fontColor;
    switch (state) {
      // case -1:
      //   boxDecoration = BoxDecoration(
      //     // color: MyColours.color_74BBBE,
      //     borderRadius: BorderRadius.only(
      //       topLeft: left
      //           ? Radius.circular(ScreenUtil().setWidth(20))
      //           : Radius.circular(0),
      //       bottomLeft: left
      //           ? Radius.circular(ScreenUtil().setWidth(20))
      //           : Radius.circular(0),
      //       topRight: right
      //           ? Radius.circular(ScreenUtil().setWidth(20))
      //           : Radius.circular(0),
      //       bottomRight: right
      //           ? Radius.circular(ScreenUtil().setWidth(20))
      //           : Radius.circular(0),
      //     ),
      //   );
      //   fontColor = MyColours.color_ffffff;
      //   break;
      case 0:
        boxDecoration = BoxDecoration(
            color: Color.fromRGBO(232, 232, 232, 1),
            // border: Border.all(
            //     color: MyColours.color_199095, width: ScreenUtil().setWidth(2)),
            borderRadius: BorderRadius.only(
              topLeft:  Radius.circular(0),
              bottomLeft: left
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
              topRight: Radius.circular(0),
              bottomRight: right
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
            ));
        fontColor = MyColours.color_199095;
        break;
      case 1:
        boxDecoration = BoxDecoration(
            color: MyColours.color_199095,
            // gradient: LinearGradient(
            //     colors: [Color(0xff199095), Color(0xff36C3C7)],
            //     begin: Alignment.topCenter,
            //     end: Alignment.bottomCenter),
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(0),
              bottomLeft: left
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
              topRight: Radius.circular(0),
              bottomRight: right
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
            ));
        fontColor = MyColours.color_fefefe;
        break;
      case 10:
        boxDecoration = BoxDecoration(
            color: MyColours.color_ffffff,
            // gradient: LinearGradient(
            //     colors: [Color(0xff199095), Color(0xff36C3C7)],
            //     begin: Alignment.topCenter,
            //     end: Alignment.bottomCenter),
            borderRadius: BorderRadius.only(
              topLeft:Radius.circular(0),
              bottomLeft: left
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
              topRight:  Radius.circular(0),
              bottomRight: right
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
            ));
        fontColor = MyColours.color_999999;
        break;
      case 11:
        boxDecoration = BoxDecoration(
            color: MyColours.color_199095,
            // gradient: LinearGradient(
            //     colors: [Color(0xff199095), Color(0xff36C3C7)],
            //     begin: Alignment.topCenter,
            //     end: Alignment.bottomCenter),
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(0),
              bottomLeft: left
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
              topRight:  Radius.circular(0),
              bottomRight: right
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
            ));
        fontColor = MyColours.color_ffffff;
        break;
      // case 2:
      //   boxDecoration = BoxDecoration(
      //       color: MyColours.color_199095,
      //       borderRadius: BorderRadius.only(
      //         topLeft: left
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //         bottomLeft: left
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //         topRight: right
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //         bottomRight: right
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //       ));
      //   fontColor = MyColours.color_fefefe;
      //   break;
      // case -2:
      //   boxDecoration = BoxDecoration(
      //       color: Color.fromRGBO(232, 232, 232, 1),
      //       borderRadius: BorderRadius.only(
      //         topLeft: left
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //         bottomLeft: left
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //         topRight: right
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //         bottomRight: right
      //             ? Radius.circular(ScreenUtil().setWidth(20))
      //             : Radius.circular(0),
      //       ));
      //   fontColor = MyColours.color_fefefe;
      //   break;
      default:
        boxDecoration = BoxDecoration(
            border: Border.all(color: MyColours.color_199095),
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(0),
              bottomLeft: left
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
              topRight: Radius.circular(0),
              bottomRight: right
                  ? Radius.circular(ScreenUtil().setWidth(20))
                  : Radius.circular(0),
            ));
        fontColor = MyColours.color_fefefe;
        break;
        break;
    }
    return Expanded(
      flex: 1,
      child: InkWell(
          onTap: onPress,
          child: Container(
            // width: width,
            padding: padding,
            // height: ScreenUtil().setWidth(height),
            decoration: boxDecoration,
            alignment: Alignment.center,
            child: Text(
                content,
                style: TextStyle(
                    color: fontColor,
                    fontWeight: fontWeight,
                    fontSize: ScreenUtil().setSp(fontSize)),
              ),
        
          )),
    );
  }
}