在按钮内部填充



有没有办法在主按钮内使用padding作为参数?在这样做的时候,我不必再使用填充小部件了,我可以选择填充:边缘插入。对称(水平:小/中或大(,

这是我的按钮类:

class SdPrimaryButton extends ElevatedButton {
SdPrimaryButton({
required String title,
required VoidCallback? onPressed,
// required Padding padding,
VoidCallback? onLongPress,
Key? key,
}) : super(
key: key,
onPressed: onPressed,
onLongPress: onLongPress,
style: ElevatedButton.styleFrom(),
child: Text(title),
);
}

这里是默认情况:正如您所看到的,每次当我必须使用按钮时,我都必须定义填充小部件以获得所需的结果。有没有什么方法可以调用我的按钮并定义按钮内部的填充,并通过将填充值设置为中小或大来实现相同的结果?

Padding(
padding: const EdgeInsets.symmetric(
horizontal: medium * 2),
child: SizedBox(
width: double.infinity,
child: SdPrimaryButton(
title: appLocalizations.labelContinue,
onPressed: () {
if (widget.checkValidation()) {
widget.pageController!.nextPage(
duration:
const Duration(milliseconds: 500),
curve: Curves.easeInOut);
_scrollToTop();
}
},
),
),
),

您可以通过填充style: ElevatedButton.styleFrom(

enum PaddingState {
small(10),
medium(20),
large(30);
final double value;
const PaddingState(this.value);
}
class SdPrimaryButton extends ElevatedButton {
SdPrimaryButton({
required String title,
required VoidCallback? onPressed,
VoidCallback? onLongPress,
PaddingState padding = PaddingState.medium,
Key? key,
}) : super(
key: key,
onPressed: onPressed,
onLongPress: onLongPress,
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(horizontal: padding.value * 2)),
child: Text(title),
);
}

相关内容

  • 没有找到相关文章