Flutter页面布局之百分百布局FractionallySizedBox

import 'package:flutter/material.dart';

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          color: Colors.blue,
          height: 50,
          child: FractionallySizedBox(
            // 对齐方式
            alignment: Alignment.center,
            // 宽度因子 1为占满整行
            widthFactor: 1,
            // 高度因子
            heightFactor: 1,
            child: Text("123"),
          ),
        ),
        appBar: AppBar(
          backgroundColor: Colors.lightBlue,
          title: Text("test"),
        ),
      ),
    );
  }
}
void main() => runApp(Test());

widthFactor为0.5的时候:

widthFactor为1的时候:

发布了66 篇原创文章 · 获赞 36 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/u013600907/article/details/102524260