import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData.light(),
home: Scaffold(
body: Center(
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 200.0, // 限制child最大高度为200
maxWidth: 100.0, // 限制child最大宽度为100
),
child: Container(
color: Colors.yellow,
),
),
)),
);
}
}
效果图:
image.png
ConstrainedBox可以限制最大高宽度,最小高端度。
网友评论