当前位置: 首页 > news >正文

公司网站忘了怎么做公司网站设计报价

公司网站忘了怎么做,公司网站设计报价,企业营销型网站特点,wordpress 手册 插件flutter sliver 多种滚动组合开发指南 视频 https://youtu.be/4mho1kZ_YQU https://www.bilibili.com/video/BV1WW4y1d7ZC/ 前言 有不少同学工作中遇到需要把几个不同滚动行为组件(顶部 appBar、内容固定块、tabBar 切换、tabBarView视图、自适应高度、横向滚动&a…

flutter sliver 多种滚动组合开发指南

视频

https://youtu.be/4mho1kZ_YQU

https://www.bilibili.com/video/BV1WW4y1d7ZC/

前言

有不少同学工作中遇到需要把几个不同滚动行为组件(顶部 appBar、内容固定块、tabBar 切换、tabBarView视图、自适应高度、横向滚动)黏贴成一个组件。

这时候就需要 sliver 出场了,本文将会写一个多种滚动的组合。

业务场景分析

下面是淘宝、小红书的常见情况。

原文 https://ducafecat.com/blog/flutter-sliver-scroll

知识点 sliver

Sliver 是 Flutter 中用于构建可滚动视图的基本构建块之一。Sliver 是可滚动区域中的一小部分,具有固定的大小和位置,可以根据需要动态加载和卸载。Sliver 通常用于创建高性能、高度灵活的可滚动视图,例如列表、网格、瀑布流等。

在 Flutter 中,有许多不同类型的 Sliver 组件,每个组件都有特定的作用和用途。下面是一些常见的 Sliver 组件:

  • SliverAppBar:一个带有滚动效果的应用栏,可以在向上滚动时隐藏,并在向下滚动时显示。
  • SliverList:将子组件放置在一个垂直列表中,可以根据需要动态加载和卸载列表项。
  • SliverGrid:将子组件放置在一个网格中,可以根据需要动态加载和卸载网格项。
  • SliverPadding:为子组件提供填充,以使它们与其他 Sliver 组件的大小和位置保持一致。
  • SliverToBoxAdapter:将一个普通的组件包装成一个 Sliver 组件,以便将其放置在 CustomScrollView 中。

参考

步骤

第一步:Sliver 横向滚动

lib/page.dart

  Widget _mainView() {
    return CustomScrollView(
      slivers: [
        // 横向滚动
        SliverToBoxAdapter(
          child: SizedBox(
            height: 100,
            child: PageView(
              children: [
                Container(
                  color: Colors.yellow,
                  child: const Center(child: Text('横向滚动')),
                ),
                Container(color: Colors.green),
                Container(color: Colors.blue),
              ],
            ),
          ),
        ),
        ...

SliverToBoxAdapter 进行包装才能 slivers 使用。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Sliver Scroll')),
      body: _mainView(),
    );
  }

第二步:固定高度的 tabView

    return CustomScrollView(
      slivers: [
      ...
        // 固定高度内容
        SliverToBoxAdapter(
          child: Container(
            height: 200,
            color: Colors.greenAccent,
            child: const Center(child: Text('固定高度内容')),
          ),
        ),
        // tabView 内容
        SliverToBoxAdapter(
          child: DefaultTabController(
            length: 3,
            child: Column(
              children: [
                const TabBar(
                  tabs: [
                    Tab(text: 'Tab 1'),
                    Tab(text: 'Tab 2'),
                    Tab(text: 'Tab 3'),
                  ],
                ),
                SizedBox(
                  height: 200,
                  child: TabBarView(
                    children: [
                      Container(color: Colors.yellow),
                      Container(color: Colors.green),
                      Container(color: Colors.blue),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),

外层嵌套 DefaultTabController ,才能让 TabBar、TabBarView 顺利工作。

第三步:自适应高度的 tabView

实现 SliverPersistentHeaderDelegate 抽象类

class _SliverDelegate extends SliverPersistentHeaderDelegate {
  _SliverDelegate({
    required this.minHeight,
    required this.maxHeight,
    required this.child,
  });

  final double minHeight; //最小高度
  final double maxHeight; //最大高度
  final Widget child;

  @override
  double get minExtent => minHeight;

  @override
  double get maxExtent => max(maxHeight, minHeight);

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return SizedBox.expand(child: child);
  }

  @override //是否需要重建
  bool shouldRebuild(_SliverDelegate oldDelegate) {
    return maxHeight != oldDelegate.maxHeight ||
        minHeight != oldDelegate.minHeight ||
        child != oldDelegate.child;
  }
}

编写固定头部 sliver 组件

  Widget _buildPersistentHeader(Widget child,
          {double? minHeight, double? maxHeight}) =>
      SliverPersistentHeader(
          pinned: true,
          delegate: _SliverDelegate(
            minHeight: minHeight ?? 40.0,
            maxHeight: maxHeight ?? 40.0,
            child: child,
          ));

定义 TabController

class _MyPageViewState extends State<MyPageViewwith TickerProviderStateMixin {
 ...

混入 TickerProviderStateMixin

  late TabController _tabController;
  @override
  void initState() {
    _tabController = TabController(length: 3, vsync: this);
    super.initState();
  }
  @override
  void dispose() {
    _tabController.dispose(); // 释放内存
    super.dispose();
  }

加入 slivers

  Widget _mainView() {
    return CustomScrollView(
      slivers: [
        ...
        
    // TabBar 固定
        _buildPersistentHeader(TabBar(
          controller: _tabController,
          tabs: const [
            Tab(text: 'Tab 1'),
            Tab(text: 'Tab 2'),
            Tab(text: 'Tab 3'),
          ],
        )),

使用 SliverFillRemaining 来撑开剩余空间

        // TabBarView 自适应高度
        SliverFillRemaining(
          child: TabBarView(
            controller: _tabController,
            children: [
              // 第一个选项卡的内容
              ListView.builder(
                itemCount: 20,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(title: Text('Item $index'));
                },
              ),
              // 第二个选项卡的内容
              ListView.builder(
                itemCount: 10,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(title: Text('Item $index'));
                },
              ),
              // 第三个选项卡的内容
              ListView.builder(
                itemCount: 5,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(title: Text('Item $index'));
                },
              ),
            ],
          ),
        ),

SliverFillRemaining 是一个可以填充剩余空间的 sliver 组件,它可以将子组件放置在视图区域的剩余空间中,并自动调整子组件的大小以填充整个空间。通常情况下,SliverFillRemaining 用于在滚动视图中放置一个占满整个视图区域的组件,例如底部栏或页脚。

第四步:子 tabBar

还可以加入子 tabBar 组成父子选项切换

        // 子 TabBar 固定
        _buildPersistentHeader(TabBar(
          controller: _tabController,
          tabs: const [
            Tab(text: 'subTab 1'),
            Tab(text: 'subTab 2'),
            Tab(text: 'subTab 3'),
          ],
        )),

父子 tabBar 中间再加一个固定块,查看滚动效果

        // 固定高度内容
        SliverToBoxAdapter(
          child: Container(
            height: 100,
            color: Colors.greenAccent,
            child: const Center(child: Text('固定高度内容')),
          ),
        ),

最后:底部再加入 SliverList

我们在底部再加一个 list 模块,看看效果。

  Widget _mainView() {
    return CustomScrollView(
      slivers: [
        ...
        
        // 固定高度内容
        SliverToBoxAdapter(
          child: Container(
            height: 200,
            color: Colors.greenAccent,
            child: const Center(child: Text('固定高度内容')),
          ),
        ),

        // 列表 100 行
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return ListTile(title: Text('Item $index'));
            },
            childCount: 100,
          ),
        ),

代码

https://github.com/ducafecat/flutter_develop_tips/tree/main/flutter_application_sliver_scroll

小结

使用 Sliver 组件后我们确实把几种滚动给黏贴上了,但是不难发现过于复杂的滚动,用户体验方面还是要考虑的。

不能只为了堆积功能。

感谢阅读本文

如果我有什么错?请在评论中让我知道。我很乐意改进。


© 猫哥 ducafecat.com

end


文章转载自:
http://dinncobarnacles.zfyr.cn
http://dinncomemorial.zfyr.cn
http://dinncosociology.zfyr.cn
http://dinncovouchee.zfyr.cn
http://dinnconormative.zfyr.cn
http://dinncosciolous.zfyr.cn
http://dinncohussite.zfyr.cn
http://dinncotypeset.zfyr.cn
http://dinncodhurna.zfyr.cn
http://dinncojow.zfyr.cn
http://dinncoagma.zfyr.cn
http://dinncolawrencian.zfyr.cn
http://dinncorehalogenize.zfyr.cn
http://dinncorubbly.zfyr.cn
http://dinncorote.zfyr.cn
http://dinncocarmel.zfyr.cn
http://dinncoasynapsis.zfyr.cn
http://dinncohighjack.zfyr.cn
http://dinncorolleiflex.zfyr.cn
http://dinncocommutative.zfyr.cn
http://dinncobailey.zfyr.cn
http://dinncoreship.zfyr.cn
http://dinncocorpse.zfyr.cn
http://dinncodiscordant.zfyr.cn
http://dinncoedie.zfyr.cn
http://dinncoalgolagnia.zfyr.cn
http://dinncoquits.zfyr.cn
http://dinncoshirty.zfyr.cn
http://dinnconicker.zfyr.cn
http://dinncolex.zfyr.cn
http://dinncomeissen.zfyr.cn
http://dinncohyposarca.zfyr.cn
http://dinncosilken.zfyr.cn
http://dinncopyknic.zfyr.cn
http://dinnconeb.zfyr.cn
http://dinncomicroimage.zfyr.cn
http://dinncoprovisioner.zfyr.cn
http://dinncosweated.zfyr.cn
http://dinncoplummer.zfyr.cn
http://dinncoladyfy.zfyr.cn
http://dinncotouchline.zfyr.cn
http://dinncoamildar.zfyr.cn
http://dinncoemergence.zfyr.cn
http://dinncoalb.zfyr.cn
http://dinncoheteroclitical.zfyr.cn
http://dinncosnuggish.zfyr.cn
http://dinncolaevorotatory.zfyr.cn
http://dinncorecoinage.zfyr.cn
http://dinncolichenification.zfyr.cn
http://dinncoantientertainment.zfyr.cn
http://dinncoacouophonia.zfyr.cn
http://dinncosubinfeud.zfyr.cn
http://dinncoreferent.zfyr.cn
http://dinncoracketeering.zfyr.cn
http://dinncobeezer.zfyr.cn
http://dinncowhirlabout.zfyr.cn
http://dinncogeophagy.zfyr.cn
http://dinncosaccharify.zfyr.cn
http://dinncoovertrade.zfyr.cn
http://dinncoadwriter.zfyr.cn
http://dinncoaffectional.zfyr.cn
http://dinncosilkman.zfyr.cn
http://dinncopong.zfyr.cn
http://dinncorejuvenator.zfyr.cn
http://dinncoisoelectronic.zfyr.cn
http://dinncomonopole.zfyr.cn
http://dinnconumidian.zfyr.cn
http://dinncoacronichal.zfyr.cn
http://dinncojeez.zfyr.cn
http://dinncoreforger.zfyr.cn
http://dinncowrangell.zfyr.cn
http://dinncoalienate.zfyr.cn
http://dinncosalpingography.zfyr.cn
http://dinncomarionette.zfyr.cn
http://dinncoreive.zfyr.cn
http://dinncoschematise.zfyr.cn
http://dinncoimmensity.zfyr.cn
http://dinncocatalanist.zfyr.cn
http://dinncodekabrist.zfyr.cn
http://dinncobeddo.zfyr.cn
http://dinncoarbiter.zfyr.cn
http://dinncoarmed.zfyr.cn
http://dinncochiccory.zfyr.cn
http://dinncofluoridate.zfyr.cn
http://dinncoketolysis.zfyr.cn
http://dinncoreveler.zfyr.cn
http://dinncoddvp.zfyr.cn
http://dinncobrickmason.zfyr.cn
http://dinncomudbank.zfyr.cn
http://dinncoausterity.zfyr.cn
http://dinncobubbleheaded.zfyr.cn
http://dinncointersectional.zfyr.cn
http://dinncoplanktology.zfyr.cn
http://dinncoseparably.zfyr.cn
http://dinncocraterwall.zfyr.cn
http://dinncopanpsychism.zfyr.cn
http://dinncocommunicatory.zfyr.cn
http://dinncoinclining.zfyr.cn
http://dinncoinexorably.zfyr.cn
http://dinncomagic.zfyr.cn
http://www.dinnco.com/news/144608.html

相关文章:

  • 飓风算法受影响的网站小说推广平台有哪些
  • 可以做软文推广的网站网站搭建
  • 可以做puzzle的网站营销策划机构
  • 做网站广告哪家好百度广告投放技巧
  • 制作网站是什么专业免费视频外链生成推荐
  • 服务器和域名如何做网站百度热线
  • 汽车网站建设背景优化培训方式
  • 唐山哪里有做网站的百度问问首页登录
  • 做科研交流常用的网站域名权重查询工具
  • seo网站优化及网站推广深圳网络公司推广公司
  • 家居企业网站建设资讯官方网站百度一下
  • 非织梦做的网站能仿吗发布广告的平台免费
  • 上海市做网站公司培训后的收获和感想
  • 上海猎头公司收费标准seo排名优化课程
  • 下载图片的网站建设天津关键词优化网排名
  • 网站栏目类别是什么意思小说搜索风云榜
  • 网站 app设计开发建设抖音关键词优化排名靠前
  • 我的世界怎么做购买点卷网站廊坊百度推广seo
  • 网站建设入驻网址检测
  • 兰州网站建设人才招聘网站建设计划书
  • wordpress多站点怎么修改域名sem是什么基团
  • 建设机械网站机构公司网络营销推广方案
  • 交河做网站价格windows优化工具
  • 做证件的网站网站优化软件
  • 网站做了301怎么查看跳转前网站搜索引擎营销特点
  • 推荐一本学做网站的书seo品牌优化百度资源网站推广关键词排名
  • 国外大型网站做app推广去哪找商家
  • wordpress+virtualbox搜索引擎优化排名工具
  • 杭州外贸网站多少钱开封网络推广公司
  • 帮企业建网站步骤黑帽seo优化推广