Flutter 基础布局Widgets之Align
发布日期:2021-05-09 04:03:51 浏览次数:18 分类:博客文章

本文共 981 字,大约阅读时间需要 3 分钟。

Align的作用是为了设置子child的对齐方式,一般作为其他控件的一个参数。

构造函数

const Align({    Key key,    this.alignment = Alignment.center,    this.widthFactor,    this.heightFactor,    Widget child  })

相关属性如下:

  • alignment 设置对齐方向
  • widthFactor 如果非空,则将其宽度设置为子元素的宽度乘以该因子,可以大于或小于1.0,但必须是正数。
  • heightFactor 如果非空,则将其高度设置为子元素的高度乘以该因子,可以大于或小于1.0,但必须是正数。

代码demo

import 'package:flutter/material.dart';void main() => runApp(  MaterialApp(    title: '图标按钮组件示例',    home: LayoutDemo(),  ),);class LayoutDemo extends StatelessWidget {  @override  Widget build(BuildContext context) {    return Scaffold(      appBar: AppBar(        title: Text('图标按钮组件示例'),      ),      body: Align(        alignment: Alignment.centerLeft,        widthFactor: 2.0,        heightFactor: 2.0,        //添加图标按钮        child: IconButton(          //图标元素          icon: Icon(Icons.volume_up,size: 48.0,),          //按钮提示          tooltip: '按下操作',          //按下事件响应          onPressed:(){            print('按下操作');          },        ),      ),    );  }}

 

 

上一篇:iOS组件化开发-发布私有库
下一篇:Dart中类的getter和setter

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年04月17日 20时52分57秒