gradient button add null

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

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

@ -95,6 +95,18 @@ class ASGradientButton extends StatefulWidget {
}
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
Widget build(BuildContext context) {
return Container(
@ -103,7 +115,11 @@ class _ASGradientButtonState extends State<ASGradientButton> {
gradient: LinearGradient(
begin: widget.begin ?? Alignment.topCenter,
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),
),

Loading…
Cancel
Save