一统天下 flutter - widget 容器类(只能有一个子): LimitedBox - 限制最大尺寸

源码 https://github.com/webabcd/flutter_demo
作者 webabcd

一统天下 flutter - widget 容器类(只能有一个子): LimitedBox - 限制最大尺寸

示例如下:

lib\widget\container\limited_box.dart

/*
 * LimitedBox - 限制最大尺寸
 */

import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    /// UnconstrainedBox 的宽高与父相同
    return UnconstrainedBox(
      /// 如果 LimitedBox 的父是无约束容器,则 LimitedBox 可以限制自己的最大宽和最大高
      child: LimitedBox(
        maxWidth: 100,
        maxHeight: 100,
        child: Container(
          color: Colors.red,
        ),
      ),
    );
  }
}

源码 https://github.com/webabcd/flutter_demo
作者 webabcd

posted @ 2023-03-27 15:34  webabcd  阅读(29)  评论(0编辑  收藏  举报