当前位置:网站首页>Flutter imitates airbnb's price range filter. (II)
Flutter imitates airbnb's price range filter. (II)
2022-06-22 12:28:00 【Still waters run deep zz】
Introduce
Flutter - Imitation Airbnb Price range filter for .( One )
Flutter - Imitation Airbnb Price range filter for .( Two )
Flutter-CustomPaint Drawing Bezier curve chart ( 3、 ... and )

The overall structure
I try to write the introduction into the notes , In this way, it is more convenient to read and understand the code .
Stack(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 15),
width: rootWidth,
height: rootHeight*0.45,
child: Stack(
children: <Widget>[
//bottom chart Bottom background chart
buildLineChart(),
//above chart The upper chart
ClipPath(
clipper: ChartClipPath(Size(30,20),// It can be based on the design drawing or through key Pass it on , It's convenient here
leftSlideImageOffset, rightSlideImageOffset),
child: buildLineChart(),
),
],
),
),
/// Price slider widget
Positioned(
bottom: 10,
child: SliderPrice(list: beanList,rootWidth: rootWidth,rootHeight: rootHeight * 0.4,
leftSlidListener: (dragging,index,leftImageKey){
//debugPrint("left ------- $dragging ------- $index");
leftSlideImageOffset = calculateSlideBlockInfo(leftImageKey);
setState(() {
});
},
rightSlidListener: (dragging,index,rightImageKey){
//debugPrint("right ------- $dragging ------- $index");
rightSlideImageOffset = calculateSlideBlockInfo(rightImageKey);
setState(() {
});
},),
),
///
],
)
ClipPath
You can see here I used ClipPath On the upper chart We have a package , By passing in a Clipper( Inherit CustomClipper) Yes, yes widget Tailoring .
In addition, the official also provided ClipOval、ClipRect、ClipRRect To facilitate the round 、 Cutting of rounded corners, rectangles, etc .
Customize Clipper Two methods need to be overridden :
1,getClip(Size size), Parameters size It's the father widget Give us the maximum size . In this method we can define path And edit at will , Then go back , Will eventually act on the child widget.
2,shouldReclip(),widget(element) Whether to redraw when refreshing , Here we go back to true.
ChartClipPath Code :
class ChartClipPath extends CustomClipper<Path>{
// Slider button size
Size slideBlockSize;
// Position of left and right sliders
Offset leftBlockOffset,rightBlockOffset;
ChartClipPath(this.slideBlockSize, this.leftBlockOffset,
this.rightBlockOffset);
// For some adaptation reasons , Add a... Here ratio Easy to adjust , In fact, if you have enough time , Write slowly to discard this variable completely ... There is no way to hurry
final double ratio =0.45;
@override
Path getClip(Size size) {
var path = Path();
// Avoid some values being empty when drawing the first stitch , So do not cut
if(slideBlockSize == null || leftBlockOffset == null || rightBlockOffset == null){
path.moveTo(0, 0);
path.lineTo(0,size.height);
path.lineTo(size.width, size.height);
path.lineTo(size.width, 0);
path.close();
return path;
}
// It's very simple here , Actually, it depends on the position of the left and right slider buttons , Walk a rectangle path, Then it is used for cutting
// Pay attention here moveTo Method , for example A To B There is no path Generated
// and lineTo The method is to generate path Of .
//path There are many sub methods , Bessel curve is also drawn here , In fact, it is very similar to Android native .
// The starting point
path.moveTo(leftBlockOffset.dx - slideBlockSize.width * ratio, 0);
// Down
path.lineTo(leftBlockOffset.dx - slideBlockSize.width * ratio, leftBlockOffset.dy);
// towards the right
path.lineTo(rightBlockOffset.dx - slideBlockSize.width * ratio, rightBlockOffset.dy);
// Up
path.lineTo(rightBlockOffset.dx - slideBlockSize.width * ratio, 0);
// Form a closure from the end point to the start point .( This is a straight line, so make sure it's what you want )
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}
The whole production is finished here .
The latter
These are just UI Drawing and functional interaction , In fact, in combination with business requirements , State handling is very complex , Mine is used in actual development provider Ongoing control , It is suggested that interested friends can learn about , Very convenient .( You can also try inheritedwidget,provider It is based on this implementation )
##DEMO
https://github.com/bladeofgod/chart_price_slider
边栏推荐
- Opencv invokes the USB camera to solve the "select timeout" problem
- Correct posture of MySQL executing script
- 什么是C语言结构体字节对齐,为什么要对齐?
- Fault tolerant heap shim applied to current process. This is usually due to previous crashes
- What is C language structure byte alignment and why?
- Small demo of QT page layout class
- View the GStreamer plug-in
- OGG-01431、01003、01151无奈的处理方式
- Flutter——实现网易云音乐的渐进式卡片切换
- 第十三届 蓝桥杯 嵌入式设计与开发项目 决赛
猜你喜欢

Redis - 4. Three new data types

In C # development, the third-party components lambdaparser, dynamicexpresso and z.expressions are used to dynamically parse / evaluate string expressions

Some concepts that the initial transformer needs to understand

Deadlock found when trying to get lock; try restarting transaction 【MySQL死锁问题解决】

仿网易云音乐的滑动冲突处理效果

Translate the tutorial Txt file

Redis - 10. Master slave replication

Redis - 8. Persistent RDB (redis database)

表格转换为LaTex格式

得物技术复杂 C 端项目的重构实践
随机推荐
OpenCV调用usb摄像头出现“select timeout”解决方法
Zcu102 PL end running water lamp
Cosmos、Polkadot
MAUI使用Masa blazor组件库
Fault tolerant heap shim applied to current process. This is usually due to previous crashes
Oracle用游标分解号码次数
When the tiflash function is pushed down, it must be known that it will become a tiflash contributor in ten minutes
【游戏】周瑜技巧
C语言itoa()函数和atoi()函数详解(整数转字符C实现)
JMeter generates test reports
Heavyweight live | bizdevops: the way to break the technology situation under the tide of digital transformation
Opencv invokes the USB camera to solve the "select timeout" problem
Flutter:剥离StatefulWidget——简化页面开发、跳转以及传值
Word技巧汇总
webrtc入门:11.Kurento中使用RtpEndpoint拉取rtp流在直播中做集群
Messari年度报告-2021
Numpy库常用功能 合并
翻译soem的 tutorial.txt 文件
V4L2像素格式及其对应的含义
Oracle用户空间统计