Flutter - AspectRatio components

Action is based on setting adjustment AspectRatio child element of the child in the aspect ratio.
AspectRatio is first extended as much as possible within the layout constraints in the allowable range, the height of the widget is determined by the ratio of the width and, in similar BoxFit Contain, as much as possible to fill a fixed area ratio.
If after all the restrictions can not find a workable size to meet, AspectRatio final priority will be to adapt the layout restrictions, while ignoring the set ratio.
 
AspectRatio component common attributes:
Attributes Explanation
aspectRatio
Aspect ratio, and ultimately may not be based on this value to the layout, will depend on the specific combination of factors, the outer layer is allowed to lay out in this ratio, it is only a reference value.
child Subassembly

 

 

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: "AspectRatioWidget",
    home: MyApp(),
  ));
}


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: 200,
        color: Colors.redAccent,
        child: AspectRatio(
          aspectRatio: 2.0/1.0,
          child: Container(
            color: Colors.green,
          ),
        ),
      ),
    );
  }
}

 

Guess you like

Origin www.cnblogs.com/chichung/p/11994046.html