我有一排只有灵活扩展的小部件:
Row(child:[
Expanded(flex:1, child: greenChild), //Expanded -> Flexible, same result
Expanded(flex:3, child: redChild),
]);
我看到的是:
...绿色的孩子是黑色的(不是绿色)——它实际上是未绘制的,并且在桌面之间拖动窗口时从白色/黑色变为白色(这是一个 Linux 目标)。
为什么是这样?我该如何解决它?
AFAICT,没有扩展/灵活作品的组合:
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
void main() {
Widget red = Container(color: Colors.red);
Widget green = Container(color: Colors.green);
Widget child = Row(
children: [
// Nope:
Expanded( flex: 1, child: green,),
Expanded(flex: 3, child: red),
// // Nope:
// Flexible( flex: 1, child: green,),
// Expanded(flex: 3, child: red),
//
// // Nope:
// Expanded( flex: 1, child: green,),
// Flexible(flex: 3, child: red),
//
// // Nope:
// Flexible( flex: 1, child: green,),
// Flexible(flex: 3, child: red),
],
);
return runApp(MaterialApp(
debugShowCheckedModeBanner: false,
// Does not help
home: Scaffold(
body: Builder(builder: (context) => child),
)));
}
Widget 检查器显示左列数据具有定义的大小:
如果我删除红色容器,我会得到下面的结果(黄色容器)。为什么这不是固定大小?这和第一个问题有关吗?
Widget child = Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.green,
child: Container(width: 50, height: 50, color: Colors.yellow)
),
),
// Expanded(
// flex: 3,
// child: Container(
// color: Colors.red,
// )),
],
);
该行为是一个 flutter bug(现已在 master 分支中修复)。