中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

嘉興網(wǎng)站公司哪家好上海seo優(yōu)化培訓(xùn)機(jī)構(gòu)

嘉興網(wǎng)站公司哪家好,上海seo優(yōu)化培訓(xùn)機(jī)構(gòu),網(wǎng)站建設(shè)論文任務(wù)書,怎么推廣一個app02_Flutter自定義Sliver組件實(shí)現(xiàn)分組列表吸頂效果 一.先上效果圖 二.列表布局實(shí)現(xiàn) 比較簡單,直接上代碼,主要使用CustomScrollView和SliverToBoxAdapter實(shí)現(xiàn) _buildSection(String title) {return SliverToBoxAdapter(child: RepaintBoundary(child: C…

02_Flutter自定義Sliver組件實(shí)現(xiàn)分組列表吸頂效果

一.先上效果圖

在這里插入圖片描述

二.列表布局實(shí)現(xiàn)

比較簡單,直接上代碼,主要使用CustomScrollView和SliverToBoxAdapter實(shí)現(xiàn)

_buildSection(String title) {return SliverToBoxAdapter(child: RepaintBoundary(child: Container(height: 50,color: Colors.brown,alignment: Alignment.center,child: Text(title),),));
}_buildItem(String title) {return SliverToBoxAdapter(child: RepaintBoundary(child: Container(padding: const EdgeInsets.symmetric(horizontal: 15),height: 70,color: Colors.cyanAccent,alignment: Alignment.centerLeft,child: Text(title),),));
}CustomScrollView(slivers: [_buildSection("蜀漢五虎將"),_buildItem("關(guān)羽"),_buildItem("張飛"),_buildItem("趙云"),_buildItem("馬超"),_buildItem("黃忠"),_buildSection("虎賁雙雄"),_buildItem("許褚"),_buildItem("典韋"),_buildSection("五子良將"),_buildItem("張遼"),_buildItem("樂進(jìn)"),_buildItem("于禁"),_buildItem("張郃"),_buildItem("徐晃"),_buildSection("八虎騎"),_buildItem("夏侯惇"),_buildItem("夏侯淵"),_buildItem("曹仁"),_buildItem("曹純"),_buildItem("曹洪"),_buildItem("曹休"),_buildItem("夏侯尚"),_buildItem("曹真")],
)

在這里插入圖片描述

三.SliverToBoxAdapter和SliverPersistentHeader

可以使用Flutter提供的SliverPersistentHeader組件實(shí)現(xiàn),在使用SliverPersistentHeader時要求我們明確指定子控件的高度,不支持吸頂上推效果,使用起來不夠靈活,所以我們參考并結(jié)合SliverToBoxAdapter和SliverPersistentHeader源碼,自己實(shí)現(xiàn)一個自適應(yīng)高度的吸頂Sliver組件,并在此基礎(chǔ)上一步步實(shí)現(xiàn)吸頂上推效果。

  • 編寫StickySliverToBoxAdapter類,繼承自SingleChildRenderObjectWidget
class StickySliverToBoxAdapter extends SingleChildRenderObjectWidget {const StickySliverToBoxAdapter({super.key,super.child});RenderObject createRenderObject(BuildContext context) => _StickyRenderSliverToBoxAdapter();}

SingleChildRenderObjectWidget類要求我們自己實(shí)現(xiàn)createRenderObject方法,返回一個RenderObject對象,而對于一個S liver組件而言,這個RenderObject必須是RenderSilver的子類。

  • 編寫_StickyRenderSliverToBoxAdapter,繼承RenderSliverSingleBoxAdapter
class _StickyRenderSliverToBoxAdapter extends RenderSliverSingleBoxAdapter {void performLayout() {// TODO: implement performLayout}}

RenderSliverSingleBoxAdapter要求子類實(shí)現(xiàn)performLayout方法,performLayout會對widegt的布局和繪制做控制,實(shí)現(xiàn)吸頂效果的關(guān)鍵就在于performLayout方法的實(shí)現(xiàn)。先依次看下SliverToBoxAdapter和SliverPersistentHeader對應(yīng)RenderObject的performLayout相關(guān)方法的實(shí)現(xiàn)。

  • RenderSliverToBoxAdapter#performLayout

void performLayout() {if (child == null) {geometry = SliverGeometry.zero;return;}final SliverConstraints constraints = this.constraints;//擺放子View,并把constraints傳遞給子Viewchild!.layout(constraints.asBoxConstraints(), parentUsesSize: true);//獲取子View在滑動主軸方向的尺寸final double childExtent;switch (constraints.axis) {case Axis.horizontal:childExtent = child!.size.width;case Axis.vertical:childExtent = child!.size.height;}final double paintedChildSize = calculatePaintOffset(constraints, from: 0.0, to: childExtent);final double cacheExtent = calculateCacheOffset(constraints, from: 0.0, to: childExtent);assert(paintedChildSize.isFinite);assert(paintedChildSize >= 0.0);//更新SliverGeometrygeometry = SliverGeometry(scrollExtent: childExtent,paintExtent: paintedChildSize,cacheExtent: cacheExtent,maxPaintExtent: childExtent,hitTestExtent: paintedChildSize,hasVisualOverflow: childExtent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0,);//更新paintOffset,由滑動偏移量constraints.scrollOffset決定setChildParentData(child!, constraints, geometry!);
}
  • RenderSliverFloatingPersistentHeader#performLayout

SliverPersistentHeader的performLayout方法中調(diào)用了updateGeometry方法去更新geometry,而吸頂?shù)年P(guān)鍵就在updateGeometry方法中,也就是paintOrigin的值。constraints.overlap的值代表前一個Sliver和當(dāng)前Sliver被覆蓋部分的高度。


double updateGeometry() {final double minExtent = this.minExtent;final double minAllowedExtent = constraints.remainingPaintExtent > minExtent ?minExtent :constraints.remainingPaintExtent;final double maxExtent = this.maxExtent;final double paintExtent = maxExtent - _effectiveScrollOffset!;final double clampedPaintExtent = clampDouble(paintExtent,minAllowedExtent,constraints.remainingPaintExtent,);final double layoutExtent = maxExtent - constraints.scrollOffset;final double stretchOffset = stretchConfiguration != null ?constraints.overlap.abs() :0.0;geometry = SliverGeometry(scrollExtent: maxExtent,paintOrigin: math.min(constraints.overlap, 0.0),paintExtent: clampedPaintExtent,layoutExtent: clampDouble(layoutExtent, 0.0, clampedPaintExtent),maxPaintExtent: maxExtent + stretchOffset,maxScrollObstructionExtent: minExtent,hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.);return 0.0;
}

四.吸頂效果實(shí)現(xiàn)

直接把上面updateGeometry中設(shè)置SliverGeometry的代碼拷貝到_StickyRenderSliverToBoxAdapter#performLayout實(shí)現(xiàn)中,maxExtent和minExtent這兩個值是由SliverPersistentHeader傳入的SliverPersistentHeaderDelegate對象提供的。這里可以自己去看SliverPersistentHeaderDelegate的源碼,就不多廢話了。我們只需要把maxExtent和minExtent這兩個值都改為子控件在主軸方向的尺寸大小即可。

 _buildSection(String title) {return StickySliverToBoxAdapter(child: RepaintBoundary(child: Container(height: 50,color: Colors.brown,alignment: Alignment.center,child: Text(title),),));}class _StickyRenderSliverToBoxAdapter extends RenderSliverSingleBoxAdapter {void performLayout() {if (child == null) {geometry = SliverGeometry.zero;return;}final SliverConstraints constraints = this.constraints;//擺放子View,并把constraints傳遞給子Viewchild!.layout(constraints.asBoxConstraints(), parentUsesSize: true);//獲取子View在滑動主軸方向的尺寸final double childExtent;switch (constraints.axis) {case Axis.horizontal:childExtent = child!.size.width;case Axis.vertical:childExtent = child!.size.height;}final double minExtent = childExtent;final double minAllowedExtent = constraints.remainingPaintExtent > minExtent ?minExtent : constraints.remainingPaintExtent;final double maxExtent = childExtent;final double paintExtent = maxExtent;final double clampedPaintExtent = clampDouble(paintExtent,minAllowedExtent,constraints.remainingPaintExtent,);final double layoutExtent = maxExtent - constraints.scrollOffset;geometry = SliverGeometry(scrollExtent: maxExtent,paintOrigin: min(constraints.overlap, 0.0),paintExtent: clampedPaintExtent,layoutExtent: clampDouble(layoutExtent, 0.0, clampedPaintExtent),maxPaintExtent: maxExtent,maxScrollObstructionExtent: minExtent,hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.);}
}

在這里插入圖片描述

仔細(xì)看上面的效果,貌似只有第一個Sliver吸頂了,我們把分組item的背景改成透明的,再來看看效果,就知道怎么回事了😄。

在這里插入圖片描述

可以看到,所有的分組section都已經(jīng)吸頂了,只不過吸頂位置都是0,并且前一個section把后一個section覆蓋了,我們下一步實(shí)現(xiàn)上推功能后,這個問題自熱而然的就解決了。

五.實(shí)現(xiàn)上推效果

在這里插入圖片描述

如圖,當(dāng)前section與前一個section重合了多少,前一個section就往上移動多少,也就是移動constraints.overlap即可,往下滑動也是同樣的道理。

//查找前一個吸頂?shù)膕ection
RenderSliver? _prev() {if(parent is RenderViewportBase) {RenderSliver? current = this;while(current != null) {current = (parent as RenderViewportBase).childBefore(current);if(current is _StickyRenderSliverToBoxAdapter && current.geometry != null) {return current;}}}return null;
}
void performLayout() {if (child == null) {geometry = SliverGeometry.zero;return;}final SliverConstraints constraints = this.constraints;//擺放子View,并把constraints傳遞給子Viewchild!.layout(constraints.asBoxConstraints(), parentUsesSize: true);//獲取子View在滑動主軸方向的尺寸final double childExtent;switch (constraints.axis) {case Axis.horizontal:childExtent = child!.size.width;case Axis.vertical:childExtent = child!.size.height;}final double minExtent = childExtent;final double minAllowedExtent = constraints.remainingPaintExtent > minExtent ?minExtent : constraints.remainingPaintExtent;final double maxExtent = childExtent;final double paintExtent = maxExtent;final double clampedPaintExtent = clampDouble(paintExtent,minAllowedExtent,constraints.remainingPaintExtent,);final double layoutExtent = maxExtent - constraints.scrollOffset;geometry = SliverGeometry(scrollExtent: maxExtent,paintOrigin: min(constraints.overlap, 0.0),paintExtent: clampedPaintExtent,layoutExtent: clampDouble(layoutExtent, 0.0, clampedPaintExtent),maxPaintExtent: maxExtent,maxScrollObstructionExtent: minExtent,hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.);//上推關(guān)鍵代碼: 當(dāng)前吸頂?shù)腟liver被覆蓋了多少,前一個吸頂?shù)腟liver就移動多少RenderSliver? prev = _prev();if(prev != null && constraints.overlap > 0) {setChildParentData(_prev()!, constraints.copyWith(scrollOffset: constraints.overlap), _prev()!.geometry!);}
}

搞定,可以洗洗睡了,嘿嘿。

在這里插入圖片描述

六.Fixed: 吸頂section點(diǎn)擊事件失效

重寫childMainAxisPosition方法返回0即可

class _StickyRenderSliverToBoxAdapter extends RenderSliverSingleBoxAdapter {...// 必須重寫,否則點(diǎn)擊事件失效。double childMainAxisPosition(covariant RenderBox child) => 0.0;}
http://www.risenshineclean.com/news/50939.html

相關(guān)文章:

  • 安裝wordpress 500 - 內(nèi)部服務(wù)器錯誤.手機(jī)百度seo怎么優(yōu)化
  • 建設(shè)網(wǎng)站要在需求長沙縣網(wǎng)絡(luò)營銷咨詢
  • 前端特效網(wǎng)站cnzz統(tǒng)計(jì)
  • photoshop怎么做網(wǎng)站百度網(wǎng)站關(guān)鍵詞排名查詢
  • 龍海市城鄉(xiāng)規(guī)劃建設(shè)局網(wǎng)站優(yōu)化網(wǎng)站內(nèi)容
  • 嘉興制作網(wǎng)站企業(yè)西安seo外包優(yōu)化
  • 贛州做公司網(wǎng)站手機(jī)網(wǎng)站智能建站
  • 嘉興企業(yè)網(wǎng)站開發(fā)可以免費(fèi)發(fā)帖的網(wǎng)站
  • asp.net做的音樂網(wǎng)站杭州最專業(yè)的seo公司
  • 網(wǎng)站自助建設(shè)平臺有哪些廣州競價托管公司
  • 做企業(yè)網(wǎng)站推廣多少錢百度官方網(wǎng)站登錄
  • 做曖曖視頻網(wǎng)站安全嗎百度營銷官網(wǎng)
  • 網(wǎng)站建設(shè)好公司好營銷網(wǎng)站做的好的公司
  • 做問卷哪個網(wǎng)站好愛站網(wǎng)關(guān)鍵詞密度
  • wordpress獲取當(dāng)前頁面鏈接seo搜索優(yōu)化專員
  • 如何在雅虎臺灣做企業(yè)網(wǎng)站站長工具綜合查詢2020
  • 網(wǎng)站 平臺建設(shè)情況介紹優(yōu)化公司網(wǎng)站排名
  • 電腦網(wǎng)站模板網(wǎng)頁模板免費(fèi)下載
  • 禪城區(qū)網(wǎng)站建設(shè)公司優(yōu)化網(wǎng)站平臺
  • 可以做軟文的網(wǎng)站營銷策略范文
  • 網(wǎng)站建設(shè)熊貓建站百度如何發(fā)布作品
  • 做網(wǎng)站需要買空間么 服務(wù)器福州百度開戶多少錢
  • 網(wǎng)站代碼在哪看查詢網(wǎng)站收錄
  • 網(wǎng)絡(luò)培訓(xùn)ppt天天seo百度點(diǎn)擊器
  • 在網(wǎng)站上保存網(wǎng)址怎么做國內(nèi)打開google網(wǎng)頁的方法
  • 設(shè)計(jì)公司網(wǎng)站建設(shè)方案百度搜索引擎營銷案例
  • wordpress 媒體庫 API抖音seo查詢工具
  • 網(wǎng)站用哪些系統(tǒng)做的好網(wǎng)絡(luò)營銷業(yè)務(wù)流程
  • 做設(shè)計(jì)必須知道的幾個網(wǎng)站嗎百度快照怎么使用
  • 怎么通過做網(wǎng)站來賺錢百度一下官方網(wǎng)址