添加 公用组件

hmxc
张萌 3 years ago
parent 44239e472f
commit 27fd4e306c

@ -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<AkuButton> {
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,
);
}
}

@ -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),
);
}

@ -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,
);
}
Loading…
Cancel
Save