Flutter使用小技巧四(持续更新...)

Flutter使用小技巧一(持续更新)
Flutter使用小技巧二(持续更新)
Flutter使用小技巧三(持续更新)

解决依赖冲突

dependency_overrides:
   # 固定版本
   third_part_dependecy_name: x.x.x

Row、Column主轴对齐方式

默认:mainAxisAlignment:MainAxisAlignment.start

  • spaceBetween: 将空闲空间均匀的分布在child wight之间
  • spaceAround:将空闲空间均匀对的分布在child wight前、后一半之间(child wight前、后一半空间相等)
  • spaceEvenly:将空闲空间均匀的分布在child wight前后之间(所有空闲空间相等)

Row
在这里插入图片描述
Column在这里插入图片描述

Future cathError 异常时添加默认返回值

Future<int> getA()async{
   
    throw 1;
  }

int i= await getA().catchError((e)=>2);

打印输出i=2

如何在Column中嵌入横着滚动的ListView

Column(children: [
    Text('HEAD'),
    
    ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: 200,
      itemBuilder(_,index) => Item()
    )
    
    Text('FOOT'),
])

很显然上面的代码一定会抛出异常,因为ListView当前滑动方向是横着的,所以它的交叉轴就是Column的主轴,我们知道Column的主轴方向是竖着的高度是无限的 ,向下回传递一个无限约束,然而在ListView确认视窗的时候交叉轴是无法确定的就会导致ListView无法布局,有一下几种办法:

  1. 固定ListView的高度:ListView外层包裹一个SizeBox
  2. ListView替换为Row,数据量小的情况下
  3. 使用Stack嵌套ListView
    我们知道Stack的 尺寸是非Positioned的那个Widget的尺寸,这样我们就可以将一个Item()作为布局用

 

                

相关推荐

  1. shell脚本使用技巧-持续更新

    2024-04-12 13:20:01       36 阅读
  2. VScode使用持续更新中。。。

    2024-04-12 13:20:01       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 13:20:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 13:20:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 13:20:01       87 阅读
  4. Python语言-面向对象

    2024-04-12 13:20:01       96 阅读

热门阅读

  1. 神经网络和反向传播算法

    2024-04-12 13:20:01       36 阅读
  2. Python教程:使用Python实现冒泡排序和快速排序

    2024-04-12 13:20:01       34 阅读
  3. 力扣练习4.11

    2024-04-12 13:20:01       42 阅读
  4. 算法基础--时间/空间复杂度

    2024-04-12 13:20:01       34 阅读
  5. 意得辑意得辑

    2024-04-12 13:20:01       34 阅读
  6. CSS:CSS的基础了解

    2024-04-12 13:20:01       41 阅读
  7. css Animation 动画-右进左出

    2024-04-12 13:20:01       40 阅读
  8. 实现移动端和pc端响应式css封装

    2024-04-12 13:20:01       44 阅读
  9. AWS Lab Streaming Data

    2024-04-12 13:20:01       27 阅读
  10. shell脚本每日练习

    2024-04-12 13:20:01       39 阅读
  11. Qt 无法连接MySQL数据库

    2024-04-12 13:20:01       42 阅读