common_button.dart 3.04 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';

class CommonButton 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;

  CommonButton(
      {@required this.onPress,
      @required this.content,
      this.state = 0,
      this.width = 250,
      this.height = 50,
      this.fontSize = 18,
      this.fontWeight = FontWeight.normal});

  @override
  Widget build(BuildContext context) {
    BoxDecoration boxDecoration;
    Color fontColor;
    switch (state) {
      case -1:
        boxDecoration = BoxDecoration(
          color: MyColours.color_d8d8d8,
          borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
        );
        fontColor = MyColours.color_ffffff;
        break;
      case 0:
        boxDecoration = BoxDecoration(
          border: Border.all(
              color: MyColours.color_199095, width: ScreenUtil().setWidth(2)),
          borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
        );
        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.circular(ScreenUtil().setWidth(10)),
        );
        fontColor = MyColours.color_fefefe;
        break;
      case 2:
        boxDecoration = BoxDecoration(
          color: MyColours.color_199095,
          borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
        );
        fontColor = MyColours.color_fefefe;
        break;
      case -2:
        boxDecoration = BoxDecoration(
          color: MyColours.color_74BBBE,
          borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
        );
        fontColor = MyColours.color_fefefe;
        break;
      default:
        boxDecoration = BoxDecoration(
          border: Border.all(color: MyColours.color_199095),
          borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
        );
        fontColor = MyColours.color_fefefe;
        break;
        break;
    }
    return Material(
      child: Ink(
        child: InkWell(
          onTap: onPress,
          child: Container(
            width: ScreenUtil().setWidth(width),
            height: ScreenUtil().setHeight(height),
            decoration: boxDecoration,
            child: Align(
              alignment: Alignment.center,
              child: Text(
                content,
                style: TextStyle(
                    color: fontColor,
                    fontWeight: fontWeight,
                    fontSize: ScreenUtil().setSp(fontSize)),
              ),
            ),
          ),
        ),
      ),
    );
  }
}