123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:ftrecruiter/comm/constants/color_constants.dart';
- import 'package:ftrecruiter/comm/utils/dark_theme_util.dart';
- // ignore: slash_for_doc_comments
- /**
- MyButton(
- fontSize: 16,
- textColor: Colors.black,
- text: "My Button的封装按钮",
- backgroundColor: ColorConstants.gray,
- onPressed: () {
- SmartDialog.compatible.showToast("MyButton的封装按钮");
- },
- radius: 15,
- side: BorderSide(color: Colors.black,width: 1.0),
- ),
- */
- class MyButton extends StatelessWidget {
- const MyButton({
- Key? key,
- required this.onPressed, //必选,点击回调
- this.text = '',
- this.fontSize = 16,
- this.textColor,
- this.disabledTextColor,
- this.backgroundColor,
- this.disabledBackgroundColor,
- this.minHeight = 48.0, //最高高度,默认48
- this.minWidth = double.infinity, //最小宽度,默认充满控件
- this.padding = const EdgeInsets.symmetric(horizontal: 16.0), //内间距,默认是横向内间距
- this.radius = 5.0, //圆角
- this.enableOverlay = true, //是否支持水波纹效果,不过这个效果对比InkWell比较克制,推荐开启
- this.elevation = 0.0, //是否支持阴影,设置Z轴高度
- this.shadowColor = Colors.black, //阴影的颜色
- this.side = BorderSide.none, //边框的设置
- }) : super(key: key);
- final String text;
- final double fontSize;
- final Color? textColor;
- final Color? disabledTextColor;
- final Color? backgroundColor;
- final Color? disabledBackgroundColor;
- final double? minHeight;
- final double? minWidth;
- final VoidCallback? onPressed;
- final EdgeInsetsGeometry padding;
- final double radius;
- final BorderSide side;
- final bool enableOverlay;
- final double elevation;
- final Color? shadowColor;
- @override
- Widget build(BuildContext context) {
- return TextButton(
- onPressed: onPressed,
- style: ButtonStyle(
- // 文字颜色
- // MaterialStateProperty.all //各种状态都是这个颜色
- foregroundColor: MaterialStateProperty.resolveWith(
- //根据不同的状态展示不同的颜色
- (states) {
- if (states.contains(MaterialState.disabled)) {
- return DarkThemeUtil.multiColors(disabledTextColor ?? Colors.grey,
- darkColor: Colors.grey);
- }
- return DarkThemeUtil.multiColors(textColor ?? Colors.white, darkColor: Colors.white);
- },
- ),
- // 背景颜色
- backgroundColor: MaterialStateProperty.resolveWith((states) {
- if (states.contains(MaterialState.disabled)) {
- return DarkThemeUtil.multiColors(disabledBackgroundColor ?? Colors.white,
- darkColor: Colors.lightBlue);
- }
- return DarkThemeUtil.multiColors(backgroundColor ?? Colors.white,
- darkColor: ColorConstants.appBlue);
- }),
- // 水波纹
- overlayColor: MaterialStateProperty.resolveWith((states) {
- return enableOverlay
- ? DarkThemeUtil.multiColors(textColor ?? Colors.white).withOpacity(0.12)
- : Colors.transparent;
- }),
- // 按钮最小大小
- minimumSize: (minWidth == null || minHeight == null)
- ? null
- : MaterialStateProperty.all<Size>(Size(minWidth!, minHeight!)),
- padding: MaterialStateProperty.all<EdgeInsetsGeometry>(padding),
- shape: MaterialStateProperty.all<OutlinedBorder>(
- RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(radius),
- ),
- ),
- side: MaterialStateProperty.all<BorderSide>(side),
- elevation: MaterialStateProperty.all<double>(elevation),
- shadowColor: MaterialStateProperty.all<Color>(
- DarkThemeUtil.multiColors(shadowColor ?? Colors.black, darkColor: Colors.white)),
- ),
- child: Text(
- text,
- style: TextStyle(fontSize: fontSize),
- ));
- }
- }
|