123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- 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;
- }
|