From 27fd4e306c31353deb5e84335175a4b37325e2e7 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Thu, 3 Jun 2021 17:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=85=AC=E7=94=A8?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/widgets/common/aku_button.dart | 56 +++++++++++++++++++ .../widgets/common/aku_cupertino_button.dart | 38 +++++++++++++ .../widgets/common/aku_material_button.dart | 52 +++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 lib/ui/widgets/common/aku_button.dart create mode 100644 lib/ui/widgets/common/aku_cupertino_button.dart create mode 100644 lib/ui/widgets/common/aku_material_button.dart diff --git a/lib/ui/widgets/common/aku_button.dart b/lib/ui/widgets/common/aku_button.dart new file mode 100644 index 0000000..ed5ebc8 --- /dev/null +++ b/lib/ui/widgets/common/aku_button.dart @@ -0,0 +1,56 @@ +import 'dart:io'; + +import 'package:aku_community_manager/ui/widgets/common/aku_cupertino_button.dart'; +import 'package:aku_community_manager/ui/widgets/common/aku_material_button.dart'; +import 'package:flutter/material.dart'; + +class AkuButton extends StatefulWidget { + @required + final Widget child; + final double height; + final double radius; + final EdgeInsets padding; + @required + final VoidCallback onPressed; + final Color color; + final double width; + AkuButton({ + Key key, + this.child, + this.height = 0, + this.radius = 0, + this.onPressed, + this.padding = EdgeInsets.zero, + this.color = Colors.transparent, + this.width = 0, + }) : super(key: key); + + @override + _AkuButtonState createState() => _AkuButtonState(); +} + +class _AkuButtonState extends State { + bool get isIOS => Platform.isIOS; + @override + Widget build(BuildContext context) { + return isIOS + ? AkuCupertinoButton( + onPressed: widget.onPressed, + child: widget.child, + radius: widget.radius, + minHeight: widget.height, + padding: widget.padding, + color: widget.color, + minWidth: widget.width, + ) + : AkuMaterialButton( + onPressed: widget.onPressed, + child: widget.child, + radius: widget.radius, + height: widget.height, + padding: widget.padding, + color: widget.color, + minWidth: widget.width, + ); + } +} diff --git a/lib/ui/widgets/common/aku_cupertino_button.dart b/lib/ui/widgets/common/aku_cupertino_button.dart new file mode 100644 index 0000000..b0ebc94 --- /dev/null +++ b/lib/ui/widgets/common/aku_cupertino_button.dart @@ -0,0 +1,38 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class AkuCupertinoButton extends CupertinoButton { + final VoidCallback onPressed; + final Widget child; + final Color color; + final EdgeInsetsGeometry padding; + final double radius; + final double minHeight; + final Color nullColor; + final double minWidth; + + AkuCupertinoButton({ + Key key, + @required this.onPressed, + @required this.child, + this.color = Colors.transparent, + this.padding = EdgeInsets.zero, + this.radius = 0, + this.minHeight = 0, + this.nullColor, + this.minWidth, + }) : super( + key: key, + child: Container( + alignment: Alignment.center, + constraints: BoxConstraints(minWidth: minWidth), + child: child, + ), + color: color, + onPressed: onPressed, + padding: padding, + borderRadius: BorderRadius.circular(radius), + minSize: minHeight, + disabledColor: nullColor ?? color.withAlpha(170), + ); +} \ No newline at end of file diff --git a/lib/ui/widgets/common/aku_material_button.dart b/lib/ui/widgets/common/aku_material_button.dart new file mode 100644 index 0000000..fffe77d --- /dev/null +++ b/lib/ui/widgets/common/aku_material_button.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; + +class AkuMaterialButton extends MaterialButton { + final VoidCallback onPressed; + final double elevation; + final double disabledElevation; + final double focusElevation; + final double highlightElevation; + final double hoverElevation; + final double height; + final double minWidth; + final double radius; + final EdgeInsets padding; + final Color color; + final Color nullColor; + + final Widget child; + AkuMaterialButton({ + Key key, + @required this.onPressed, + this.elevation = 0, + this.disabledElevation = 0, + this.focusElevation = 0, + this.highlightElevation = 0, + this.hoverElevation = 0, + this.height = 48, + this.minWidth = 0, + this.radius = 0, + this.padding = EdgeInsets.zero, + @required this.child, + this.color = Colors.transparent, + this.nullColor = Colors.transparent, + }) : super( + key: key, + onPressed: onPressed, + elevation: elevation, + disabledElevation: disabledElevation, + focusElevation: focusElevation, + highlightElevation: highlightElevation, + hoverElevation: hoverElevation, + height: height, + minWidth: minWidth, + padding: padding, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(radius), + ), + child: child, + color: color, + disabledColor: nullColor, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + ); +}