简体   繁体   English

flutter 定制设计形状

[英]flutter custom design shape

i have this design(shown in the photo) which I want to code, I tried making the shape as an svg pic and put it in a container but I don't think that's the best way and also there is a margin on the sides that won't go even when I remove the padding(shown in the picture on the right)我有这个我想编码的设计(如图所示),我尝试将形状制作为 svg 图片并将其放入容器中,但我认为这不是最好的方式,而且侧面也有边距即使我删除了填充,也不会 go(如右图所示)

my code is:我的代码是:

Scaffold(
        body: SafeArea(
          child: SingleChildScrollView(
            child: Align(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [

                  Padding(
                    padding: EdgeInsets.all(SizeConfig.blockSizeHorizontal * 2),
                    child: buildLocalImage('assets/images/shape.svg'),
                  ),

在此处输入图像描述

The margin propably stems from the SafeArea.边距可能来自 SafeArea。 Since you are in the body of a Scaffold, you probably do not need it there.由于您位于 Scaffold 的主体中,因此您可能不需要它。 Try to remove the SafeArea first, before you try sommething like a custom painter.先尝试删除 SafeArea,然后再尝试自定义画家之类的东西。

Also, you could use a package like flutter_svg to embed the SVG shape into your app.此外,您可以使用诸如 flutter_svg 之类的package将 SVG 形状嵌入到您的应用程序中。 This allows you to use the usual fitting parameters to position the shape.这允许您使用通常的拟合参数来调整 position 的形状。

To position the logo according to your mockup, you have to stack it over the SVG background. position 根据您的模型制作徽标,您必须将其堆叠在 SVG 背景上。 Use the stack widget for that.为此使用堆栈小部件。

Your options are:您的选择是:

  1. Clipping using CustomClipper class使用CustomClipper class进行剪辑

  2. Drawing using CustomPainter class使用CustomPainter class绘图

  3. Drawing using RenderBox class使用RenderBox class绘图

  4. Stacking clipped containers with Stack class使用Stack class堆叠已剪裁的容器

  5. Using images使用图像

It's unclear what the best option is because I am not sure what you will do after this is drawn (gesture detect, position, etc).目前还不清楚最好的选择是什么,因为我不确定在绘制之后你会做什么(手势检测、position 等)。 But I would say option 2 is generally the most common.但我会说选项 2 通常是最常见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM