当前位置:网站首页>Shutter widget: centerslice attribute
Shutter widget: centerslice attribute
2022-07-03 12:06:00 【J_ D_ Chi】
Write it at the front
stay Flutter In the project , Sometimes I use Android The one on the is called dot 9 Picture things . spot 9 Graph is a kind of graph that allows us to set a certain direction , Stretch a part of the picture .
As far as I know ,Flutter Up to point 9 The support of figure is similar to Android There are some differences in .Flutter It's when we decide 9 After the central area of the figure , It will automatically stretch horizontally and vertically . It seems that if the picture is a more standardized graphic , Ordinary pictures are also ok .
Content
stay Flutter On , There will be a control called centerSlice Properties of , To help us deal with some 9 chart .
/// The center slice for a nine-patch image.
///
/// The region of the image inside the center slice will be stretched both
/// horizontally and vertically to fit the image into its destination. The
/// region of the image above and below the center slice will be stretched
/// only horizontally and the region of the image to the left and right of
/// the center slice will be stretched only vertically.
///
/// The stretching will be applied in order to make the image fit into the box
/// specified by [fit]. When [centerSlice] is not null, [fit] defaults to
/// [BoxFit.fill], which distorts the destination image size relative to the
/// image's original aspect ratio. Values of [BoxFit] which do not distort the
/// destination image size will result in [centerSlice] having no effect
/// (since the nine regions of the image will be rendered with the same
/// scaling, as if it wasn't specified).
final Rect? centerSlice;
centerSlice yes Rect type , So it's a rectangle .
Take this picture for example , Its size is 50 * 50.
In use , Let's first determine its middle rectangle , That is to say centerSlice, Then it will extend along the four sides of the rectangle , Divide the picture into 9 Parts of :
Then we take the position of its central rectangle :
Rect.fromLTRB(15, 15, 35, 35)
here Rect.fromLTRB(15, 15, 35, 35) It's the rectangle in the middle .
Suppose we run the following code
Image.asset(
'assets/black_square.png',
height: 100,
width: 350,
centerSlice: Rect.fromLTRB(15, 15, 35, 35),
)
Then the actual effect is here 9 In two parts , With centerSlice As the central part , The rectangular part of the four corners will not change , The left, right, upper and lower parts will be stretched . So in the figure of our example , The fillet will not be deformed due to stretching .
Column(
children: [
Container(
height: 100,
width: 330,
color: Colors.red,
),
Image.asset(
'assets/black_square.png',
height: 100,
width: 330,
centerSlice: Rect.fromLTRB(15, 15, 35, 35),
),
Image.asset(
'assets/black_square.png',
height: 100,
width: 330,
fit: BoxFit.fill,
),
Image.asset(
'assets/black_square.png',
height: 100,
width: 330,
fit: BoxFit.fitWidth,
)
],
)

Reference resources
How to display .9.png format of a picture in flutter?
Flutter centerSlice .9 The understanding of graph
边栏推荐
- vulnhub之raven2
- Solve msvcp120d DLL and msvcr120d DLL missing
- pragma-pack语法与使用
- During FTP login, the error "530 login incorrect.login failed" is reported
- 网络通讯之Socket-Tcp(一)
- Colleagues wrote a responsibility chain model, with countless bugs
- Groovy测试类 和 Junit测试
- XML (DTD, XML parsing, XML modeling)
- Go language to realize static server
- MySQL searches and sorts out common methods according to time
猜你喜欢
随机推荐
(构造笔记)GRASP学习心得
Test classification in openstack
Qt OpenGL 旋转、平移、缩放
OpenGL shader use
Deploying WordPress instance tutorial under coreos
Raven2 of vulnhub
OPenGL 基本知识(根据自己理解整理)
Dynamically monitor disk i/o with ZABBIX
利用Zabbix动态监控磁盘I/O
vulnhub之Ripper
OpenGL 索引缓存对象EBO和线宽模式
Nestjs configuration service, configuring cookies and sessions
Unity3d learning notes 5 - create sub mesh
cgroup简介
How to convert a numeric string to an integer
OpenGL 着色器使用
Cacti monitors redis implementation process
836. Merge sets (day 63) and search sets
PHP export word method (one MHT)
Go语言实现静态服务器

![[official MySQL document] deadlock](/img/2d/04e97d696f20c2524701888ea9cd10.png)







