首页 Flutter深入浅出组件篇---Center、完结
文章
取消

Flutter深入浅出组件篇---Center、完结

Center介绍

Center就是将子组件进行一个居中展示,它继承自Align,因为Align默认的对齐方式是居中的,所以它能实现居中效果,如果Center的尺寸没有受到限制,那么它将尽可能大。

示例代码

本文中很多效果都没有截图,可下载源代码运行项目 源代码地址,或者通过视频教程查看 视频教程地址

什么情况下使用Center?

当我们需要对子组件进行居中的时候使用Center

Center的属性和说明

字段 属性 描述
widthFactor double 宽度系数
heightFactor double 高度系数
child Widget 子组件

Center使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import 'package:flutter/material.dart';

class CenterExample extends StatefulWidget {
  @override
  _CenterExampleState createState() => _CenterExampleState();
}

class _CenterExampleState extends State<CenterExample> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("AlignExample"),
      ),
      body: Center(
        child: Text("Jimi"),
      ),
    );
  }
}

效果展示

完结

我们对Flutter的所有容器类组件进行了一个讲解,那么此篇幅就已经完结了,在接下来我们继续讲解Flutter的基础类组件。

本文由作者按照 CC BY 4.0 进行授权