flutter 组件 Stepper,Step,Padding,Align,Center,FittedBox,AspectRatio,ConstrainedBox

2023-10-27

1.Stepper,Step

Stepper({
    Key key,
    @required this.steps, //step类型的子集
    this.physics,
    this.type = StepperType.vertical, //方向
    this.currentStep = 0, //当前位置
    this.onStepTapped, //点击事件
    this.onStepContinue, //继续事件
    this.onStepCancel, //返回
    this.controlsBuilder, //操作的控制builder
  })
const Step({
    @required this.title, //标题
    this.subtitle, //副标题
    @required this.content, //内容
    this.state = StepState.indexed, //图标的状态
    this.isActive = false, //是否是active
})
import 'package:flutter/material.dart';

class MyComponent extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyComponent();
  }
}

class _MyComponent extends State<MyComponent> {
  int _step = 0;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Component"),
      ),
      body: Column(
        children: <Widget>[
          Stepper(
            currentStep: _step,

            //继续的回调
            onStepContinue: () {
              if (_step == 3) {
                setState(() {
                  _step = 0;
                });
              } else {
                setState(() {
                  _step += 1;
                });
              }
            },
            //控制按钮的builder
            controlsBuilder: (BuildContext context,
                {VoidCallback onStepContinue, VoidCallback onStepCancel}) {
              return Row(
                children: <Widget>[
                  RaisedButton(
                    onPressed: onStepContinue,
                    child: const Text('继续'),
                  )
                ],
              );
            },
            steps: [
              Step(
                  title: Text("标题"),
                  content: Container(
                    width: 150.0,
                    height: 50.0,
                    color: Colors.black12,
                  ),
                  state: StepState.complete,
                  isActive: true),
              Step(
                title: Text("标题"),
                content: Text("内容"),
                state: StepState.disabled,
              ),
              Step(
                title: Text("标题"),
                content: Text("内容"),
                state: StepState.editing,
              ),
              Step(
                  title: Text("标题"),
                  subtitle: Text("副标题"),
                  content: Text("内容"),
                  isActive: true)
            ],
          )
        ],
      ),
    );
  }
}

     

     

2.Padding,Align,Center 

const Padding({
    Key key,
    @required this.padding, //间距padding
    Widget child, //子集
})
//居中

//当widthFactor和heightFactor为null的时候,
//当其有限制条件的时候,Align会根据限制条件尽量的扩展自己的尺寸,
//当没有限制条件的时候,会调整到child的尺寸;

//当widthFactor或者heightFactor不为null的时候,
//Aligin会根据factor属性,扩展自己的尺寸,
//例如设置widthFactor为2.0的时候,那么,Align的宽度将会是child的两倍


const Center({ 
    Key key, 

    double widthFactor, 

    double heightFactor, 

    Widget child 

})
const Align({
    Key key,
    this.alignment = Alignment.center, //对齐方式
    this.widthFactor, //同上
    this.heightFactor, //同上
    Widget child, //子集
})
import 'package:flutter/material.dart';

class MyIos extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyIos();
  }
}

class _MyIos extends State<MyIos> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Layout"),
      ),
      body: Column(
        children: <Widget>[
          //Container有对齐方式,这里只是测试
          //Align
          Container(
            width: 200.0,
            height: 100.0,
            color: Colors.black12,
            child: Padding(
              padding: EdgeInsets.all(10.0),
              child: Align(
                alignment: Alignment.bottomRight,
                child: Text("内容很少"),
              ),
            ),
          ),
          //Container有对齐方式,这里只是测试
          //Center
          Container(
            margin: EdgeInsets.only(top: 15.0),
            width: 200.0,
            height: 100.0,
            color: Colors.black12,
            child: Padding(
              padding: EdgeInsets.all(10.0),
              child: Center(
                child: Text("内容"),
              ),
            ),
          )
        ],
      ),
    );
  }
}

3.FittedBox

//类似于图片的那种缩放满足容器的大小的那种盒模型

//如果外部有约束的话,按照外部约束调整自身尺寸,然后缩放调整child,按照指定的条件进行布局

//如果没有外部约束条件,则跟child尺寸一致,指定的缩放以及位置属性将不起作用

const FittedBox({
    Key key,
    this.fit = BoxFit.contain, //类似图片的fit
    this.alignment = Alignment.center, //对齐方式
    Widget child, //子集
})

 

import 'package:flutter/material.dart';

class MyIos extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyIos();
  }
}

class _MyIos extends State<MyIos> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Layout"),
      ),
      body: Column(
        children: <Widget>[
          Container(
            width: 200.0,
            height: 200.0,
            color: Colors.black12,
            child: FittedBox(
              fit: BoxFit.contain,
              child: Text("567"),
            ),
          ),
          Container(
            width: 200.0,
            margin: EdgeInsets.only(top: 15.0),
            height: 200.0,
            color: Colors.black12,
            child: FittedBox(
              alignment: Alignment.bottomRight,
              fit: BoxFit.scaleDown,
              child: Text("567"),
            ),
          )
        ],
      ),
    );
  }
}

4.AspectRatio

//场景是相机,相机的预览尺寸都是固定的几个值,因此不能随意去设置相机的显示区域,必须按照比率进行显示
//AspectRatio首先会在布局限制条件允许的范围内尽可能的扩展,widget的高度是由宽度和比率决定的,类似于BoxFit中的contain,按照固定比率去尽量占满区域
//如果在满足所有限制条件过后无法找到一个可行的尺寸,AspectRatio最终将会去优先适应布局限制条件,而忽略所设置的比率

const AspectRatio({
    Key key,
    @required this.aspectRatio, //宽高比
    Widget child,
}) 

 

Container(
   height: 200.0,
   child: new AspectRatio(
       aspectRatio: 1.5,
       child: new Container(
          color: Colors.red,
       ),
   ),
)

// 300 x 200的区域

5.ConstrainedBox

//约束条件

ConstrainedBox({
    Key key,
    @required this.constraints,
    Widget child,
})

const BoxConstraints({
    this.minWidth = 0.0,
    this.maxWidth = double.infinity,
    this.minHeight = 0.0,
    this.maxHeight = double.infinity,
});

 

//最小宽度和最小高度
//Container宽度全屏,高度只有150 
ConstrainedBox(
    constraints: BoxConstraints(
       minWidth: 100.0,
       minHeight: 150.0
    ),
    child: Container(
       color: Colors.black12,
    ),
 )

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

flutter 组件 Stepper,Step,Padding,Align,Center,FittedBox,AspectRatio,ConstrainedBox 的相关文章

随机推荐

  • top-k的应用

    top k的应用 topk指的是 保存一段数据的最大或者最小的k位数 在code中或者工程中右很重要的应用 举例 查询超大量数据中 最小或者最大的 第 k位数 正常使用排序 缺点 内存占用会超出正常范围 相对简单的做法是 遍历K次 每次选出
  • Flex 发布模式

    Flex 平台支持范围广泛的发布模式 它们是 1 客户端模式 即应用程序只运行在客户端上而不需要服务器资源 2 使用简单的RPC 访问服务器数据 即使用HTTPService HTTP GET 或POST 请求 和WebService 通过
  • LeetCode——021

    21 Merge Two Sorted Lists My Submissions QuestionEditorial Solution Total Accepted 122136 Total Submissions 345783 Diffi
  • JAVA字符流InputStreamReader读取文本

    二 字符流 1 单个字符读取 public static void main String args try InputStreamReader in new InputStreamReader new FileInputStream D
  • 简体ProDAD Mercalli SAL 6.0全网唯一系统讲解课中文教程

    ProDAD Mercalli SAL 镜头抖动处理软件 是一个视频防抖插件 可以固定拍摄时的图像抖动 消除摄像机拍摄视频时抖动 颠簸和颤抖的影响 提高画面质量 是进行后期摄影图像编辑必不可少的插件之一 虽然ProDAD Mercalli
  • 小学生机器人编程知识

    小学生机器人编程知识 现在的家长在培养孩子的学习方面也是非常的认真的 会给孩子选择一些能够有利于孩子成长的课程 就拿现在很多的家长给孩子选择少儿编程的课程来说 他们想要孩子去学习机器人编程的课程 但是他们对于小学生机器人编程知识并不是很清楚
  • windows下设置redis服务开机后自动启动

    1 配置环境变量 在path配置环境变量 2 在redis安装目录下打开cmd 输入如下代码 redis server exe service install redis windows conf loglevel verbose 3 这样
  • MAC下搭建Android Studio

    JDK1 8安装 1 到 http www oracle com technetwork java javase downloads jdk8 downloads 2133151 html 下载jdk8 2 双击安装 3 安装完成 在命令行
  • 7-13 日K蜡烛图 (15分)

    7 13 日K蜡烛图 15分 股票价格涨跌趋势 常用蜡烛图技术中的K线图来表示 分为按日的日K线 按周的周K线 按月的月K线等 以日K线为例 每天股票价格从开盘到收盘走完一天 对应一根蜡烛小图 要表示四个价格 开盘价格Open 早上刚刚开始
  • Java复习-20-接口(1)

    接口的定义及使用 如果相对外部隐藏全部的实现细节 就要通过接口来实现 接口的定义 使用interface关键字来定义 由于接口描述的是一个公共的定义标准 所以在接口之中所有的抽象方法的访问权限都为public interface IMess
  • 数据库种类有什么?三种不同数据库介绍

    一 数据库种类有哪些 早期较为时兴的数据库种类有三种 分别是层次式数据库 网络式数据库和关系型数据库 而在如今的互联网中 最常见的数据库种类主要有2种 即关系型数据库和非关系型数据库 二 层次数据库介绍 层次数据库是最开始研制的数据库系统软
  • python获取时间前一天

    可以使用 Python 的 datetime 模块来获取时间前一天的日期 首先 需要导入 datetime 模块 import datetime 然后 可以使用 datetime 模块中的 datetime datetime now 函数获
  • GET、POST、PUT、DELETE等用法

    1 向服务器请求数据 GET get请求是用来获取数据的 只是用来查询数据 不对服务器的数据做任何的修改 新增 删除等操作 get请求会把请求的参数附加在URL后面 2 提交资源到服务器 post post请求一般是对服务器的数据做改变 常
  • so部标协议模拟服务器,808部标协议

    满意答案 豆 浆 2016 10 12 采纳率 58 等级 25 已帮助 62843人 基于部标JT T 808协议及数据格式的GPS服务器 2011年5月10日中国交通通信信息中心下发了 印发道路运输车辆卫星定位系统平台和道路运输车辆卫星
  • python 43行 写一个天气查询爬虫+GUI图形界面化

    这个爬虫爬的是 墨迹天气 https tianqi moji com weather china henan xinxiang 分析了一下这个网址 不同城市的网址就后边的的拼音不同 这时候就只需拼接用户输入的网址就可得到要查询的网址 然后通
  • Putty基础教程之(一).入门命令学习及编写HTML

    这篇文章主要介绍Putty的基础用法 同时通过Putty来编辑HTML文件 一方面是自己最近学习的在线笔记 另一方面希望文章对你有所帮助 Putty是Windows下操作Linux命令的小工具 也是一个跨平台的远程登陆工具 非常好用 常见命
  • 【IT之路】MyEclipse部署java web项目到Tomcat

    1 Java web 项目部署发布到tomcat 2 启动tomcat
  • 测试分布式系统的线性一致性

    测试分布式系统的线性一致性 一 介绍 正确实现一个分布式系统是非常有挑战的一件事情 因为需要很好的处理并发和失败这些问题 网络包可能被延迟 重复 乱序或者丢弃 机器可能在任何时候宕机 即使一些设计被论文证明是正确的 也仍然很难再实现中避免
  • css3弹性盒子模型(Flex)

    css3弹性盒子模型 CSS3 弹性盒子 Flex Box 设置弹性盒子 容器的属性 设置主轴方向 flex direction 设置主轴方向上对齐方式 justify content 设置副轴方向上的对齐方式 align items 设置
  • flutter 组件 Stepper,Step,Padding,Align,Center,FittedBox,AspectRatio,ConstrainedBox

    1 Stepper Step Stepper Key key required this steps step类型的子集 this physics this type StepperType vertical 方向 this current