gradient button add null

null_safety
小赖 4 years ago
parent 25efdd955f
commit 7257ecf174

@ -111,6 +111,13 @@ class _ExampleButtonState extends State<ExampleButton> {
onPressed: () {}, onPressed: () {},
), ),
), ),
ListTile(
title: Text('pay'),
trailing: ASGradientButton.pay(
title: '支付',
onPressed: null,
),
),
ListTile( ListTile(
title: Text('opration'), title: Text('opration'),
trailing: ASGradientButton.operation( trailing: ASGradientButton.operation(

@ -95,6 +95,18 @@ class ASGradientButton extends StatefulWidget {
} }
class _ASGradientButtonState extends State<ASGradientButton> { class _ASGradientButtonState extends State<ASGradientButton> {
bool get isNullFunc => widget.onPressed == null;
List<Color> get colors {
if (widget.colors == null)
return null;
else {
return List.generate(
widget.colors.length,
(index) => widget.colors[index].withOpacity(isNullFunc ? 0.5 : 1),
);
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -103,7 +115,11 @@ class _ASGradientButtonState extends State<ASGradientButton> {
gradient: LinearGradient( gradient: LinearGradient(
begin: widget.begin ?? Alignment.topCenter, begin: widget.begin ?? Alignment.topCenter,
end: widget.end ?? Alignment.bottomCenter, end: widget.end ?? Alignment.bottomCenter,
colors: widget.colors ?? [kDarkPrimaryColor, kLightPrimaryColor], colors: colors ??
[
kDarkPrimaryColor.withOpacity(isNullFunc ? 0.5 : 1),
kLightPrimaryColor.withOpacity(isNullFunc ? 0.5 : 1),
],
), ),
borderRadius: BorderRadius.circular(widget.radius ?? 20.w), borderRadius: BorderRadius.circular(widget.radius ?? 20.w),
), ),

Loading…
Cancel
Save