import 'package:ctjt_flutter/common/styles.dart'; import 'package:ctjt_flutter/common/utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; /* ---------------------------------大提交按钮-------------------------------- */ class BigSButton extends StatelessWidget { static var _defaultPadding = EdgeInsets.only(top: 75.h); BigSButton( {Key? key, required this.text, this.padding, this.milliseconds = 500, this.vibrateDuration = Utils.DefaultVibrateDuration, required this.onPressed}) : super(key: key); final String text; final EdgeInsetsGeometry? padding; final Function onPressed; final int milliseconds; final int vibrateDuration; @override Widget build(BuildContext context) { bool _isCan = true; return Container( // 设定尺寸的容器 width: double.infinity, // 占满宽度 height: 230.0.h, padding: null == this.padding ? _defaultPadding : this.padding, child: ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.white), foregroundColor: MaterialStateProperty.all(Colors.white), shape: MaterialStateProperty.all(RoundedRectangleBorder( borderRadius: BorderRadius.circular(ScreenUtil().radius(20)))), elevation: MaterialStateProperty.all(ScreenUtil().radius(7.5)), ), child: Text(this.text, style: Styles.btnFontStyle), // 圆角 onPressed: () { Utils.vibrate(duration: this.vibrateDuration); // 震动 if (_isCan) { this.onPressed(); _isCan = false; // 不能多次点击 Future.delayed(Duration(milliseconds: this.milliseconds), () { _isCan = true; }); } }, ), ); } } /* --------------------------------大文本按钮--------------------------------- */ class BigTButton extends StatelessWidget { static var _defaultPadding = EdgeInsets.only(top: 25.h); BigTButton( {Key? key, required this.text, this.padding, this.milliseconds = 500, this.vibrateDuration = Utils.DefaultVibrateDuration, required this.onPressed}) : super(key: key); final String text; final EdgeInsetsGeometry? padding; final Function onPressed; final int milliseconds; final int vibrateDuration; @override Widget build(BuildContext context) { bool _isCan = true; return Padding( padding: null == this.padding ? _defaultPadding : this.padding!, child: OutlinedButton( style: ButtonStyle( padding: MaterialStateProperty.all(EdgeInsets.all(0)), side: MaterialStateProperty.all(BorderSide.none), ), child: Text(this.text, textAlign: TextAlign.left, overflow: TextOverflow.ellipsis, style: Styles.btnFontStyle), //color: Colors.red, onPressed: () { Utils.vibrate(duration: this.vibrateDuration); // 震动 if (_isCan) { this.onPressed(); _isCan = false; // 不能多次点击 Future.delayed(Duration(milliseconds: this.milliseconds), () { _isCan = true; }); } }, ), ); } } /* ----------------------------------图标按钮--------------------------------- */ class IButton extends IconButton { IButton({ Key? key, double iconSize = 24.0, VisualDensity? visualDensity, EdgeInsetsGeometry padding = const EdgeInsets.all(8.0), AlignmentGeometry alignment = Alignment.center, double? splashRadius, required Widget icon, Color? color, Color? focusColor, Color? hoverColor, Color? highlightColor, Color? splashColor, Color? disabledColor, required VoidCallback onPressed, MouseCursor mouseCursor = SystemMouseCursors.click, FocusNode? focusNode, bool autofocus = false, String? tooltip, bool enableFeedback = true, BoxConstraints? constraints, this.vibrateDuration = Utils.DefaultVibrateDuration, }) : super( key: key, iconSize: iconSize, visualDensity: visualDensity, padding: padding, alignment: alignment, splashRadius: splashRadius, icon: icon, color: color, focusColor: focusColor, hoverColor: hoverColor, highlightColor: highlightColor, splashColor: splashColor, disabledColor: disabledColor, onPressed: () { Utils.vibrate(duration: vibrateDuration); // 震动 onPressed(); }, mouseCursor: mouseCursor, focusNode: focusNode, autofocus: autofocus, tooltip: tooltip, enableFeedback: enableFeedback, constraints: constraints, ); final int vibrateDuration; } /* ----------------------------------文本按钮--------------------------------- */ class TButton extends TextButton { TButton({ Key? key, required VoidCallback onPressed, VoidCallback? onLongPress, ButtonStyle? style, FocusNode? focusNode, bool autofocus = false, Clip clipBehavior = Clip.none, required Widget child, this.vibrateDuration = Utils.DefaultVibrateDuration, }) : super( key: key, onPressed: () { Utils.vibrate(duration: vibrateDuration); // 震动 onPressed(); }, onLongPress: onLongPress, style: style, focusNode: focusNode, autofocus: autofocus, clipBehavior: clipBehavior, child: child, ); final int vibrateDuration; }