一统天下 flutter - widget 容器类(只能有一个子): Center - 居中对齐

发布时间 2023-03-22 21:14:10作者: webabcd

一统天下 flutter https://github.com/webabcd/flutter_demo
作者 webabcd

一统天下 flutter - widget 容器类(只能有一个子): Center - 居中对齐

示例如下:

lib\widget\container\center.dart

/*
 * Center - 居中对齐
 *
 * Center 继承自 Align,建议能用 Center 就别用 Align
 */

import 'package:flutter/material.dart';

class CenterDemo extends StatelessWidget {
  const CenterDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: 50,
        height: 50,
        color: Colors.red,
      ),
    );
  }
}

一统天下 flutter https://github.com/webabcd/flutter_demo
作者 webabcd