Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created February 15, 2020 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlid/7fa7c962b5436d3a8deef3d4075d1473 to your computer and use it in GitHub Desktop.
Save ryanlid/7fa7c962b5436d3a8deef3d4075d1473 to your computer and use it in GitHub Desktop.
ConstrainedBox 限定最大最小宽高布局
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: "ConstrainedBox限定最大最小宽高布局",
home: LayoutDemo(),
));
}
class LayoutDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ConstrainedBox限定最大最小宽高布局"),
),
body: ConstrainedBox(
// 设置限定值
constraints: BoxConstraints(
minWidth: 150.0,
minHeight: 220.0,
maxWidth: 220.0,
maxHeight: 220.0,
),
// 子容器
child: Container(
width: 300.0,
height: 300.0,
color: Colors.green,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment