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,
            ),
          ),
        ),
      ),
    );
  }
}

显示:


image.png

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


image.png
上一篇 下一篇

猜你喜欢

热点阅读