Flutter - 宽高比
2019-07-22 本文已影响0人
辻子路
AspectRatio这个widget是用来设置子组件的宽高比的。
import 'package:flutter/material.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: AspectRatio(
aspectRatio: 1.0 / 1.0, // 宽高比
child: Container(
color: Colors.yellow,
),
),
),
),
);
}
}
显示:

如果将1.0/1.0 改为 0.5/1.0,则显示
