[英]Custom Padding Widget on Flutter
Hello Everyone;大家好; I'm trying to make a custom widget that extends EdgeInsets class.我正在尝试制作一个扩展 EdgeInsets 类的自定义小部件。 I want a custom widget because i will use it in my project like that;我想要一个自定义小部件,因为我会在我的项目中使用它; CustomPadding.all(20) - CustomPadding.only(top: 10)
How can i use like this? CustomPadding.all(20) - CustomPadding.only(top: 10)
我怎么能这样使用? Thanks you all.谢谢大家。
I am using like this for now;我现在就这样使用;
class ProjectDecorations {
static const EdgeInsets homepage3dotsPadding = EdgeInsets.only(right: 5);
static const EdgeInsets centerImgPadding = EdgeInsets.only(top: 180);
static const EdgeInsets loginButtonTopPadding = EdgeInsets.only(top: 100);
static const EdgeInsets createAccountTopPadding = EdgeInsets.only(top: 20);
Create a file that you can name constants.dart, inside this file set your custom padding and you can name it depending on the context you'll use each one of them as follows:创建一个您可以命名为 constants.dart 的文件,在此文件中设置您的自定义填充,您可以根据上下文命名它,您将使用它们中的每一个,如下所示:
const EdgeInsets kRegularPadding = EdgeInsets.all(20);
const EdgeInsets kTopPadding = EdgeInsets.only(top: 10);
Now you can use it in your code as follows:现在您可以在代码中使用它,如下所示:
class SampleCode extends StatelessWidget {
const SampleCode({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: kRegularPadding,
margin: kTopPadding,
child: YourWidget()
);
}
}
Don't forget to import the file constants.dart不要忘记导入文件 constants.dart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.