如何修复不可见的展开小部件?

问题描述 投票:0回答:1

我有一排只有灵活扩展的小部件:

Row(child:[
   Expanded(flex:1, child: greenChild),  //Expanded -> Flexible, same result
   Expanded(flex:3, child: redChild),
]);

我看到的是:enter image description here ...绿色的孩子是黑色的(不是绿色)——它实际上是未绘制的,并且在桌面之间拖动窗口时从白色/黑色变为白色(这是一个 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 检查器显示左列数据具有定义的大小:

enter image description here

如果我删除红色容器,我会得到下面的结果(黄色容器)。为什么这不是固定大小?这和第一个问题有关吗?

  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,
      //     )),
    ],
  );

enter image description here

flutter
1个回答
0
投票

该行为是一个 flutter bug(现已在 master 分支中修复)。

https://github.com/flutter/flutter/issues/151021

© www.soinside.com 2019 - 2024. All rights reserved.