Flutter:最小高度、扩展和 SingleChildScrollView?

Jam*_*len 7 flutter flutter-layout

我不知道如何在 Flutter 中进行这种布局。我想要实现的是:

  • 我有一列,包含一个固定高度的子项(标题文本小部件)和两个扩展小部件。我使用扩展是因为我希望每个人共享剩余屏幕的一半。
  • 当方向更改为横向时,没有足够的空间来正确显示展开的小部件的内容。所以我想要的是在这两个小部件上应用最小高度,并使其变得可滚动。

我希望这是有道理的 - 我不知道如何实现这一点。我已经尝试了很多扩展、灵活、列、SingleChildScrollView、最小列轴大小等组合,但我尝试的一切都会导致某种无限高度异常。这甚至可能吗?

这是一些示例代码:以下工作正常。如何在两个占位符上实现滚动和最小高度?

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            Text("Title"),
            // I need to apply a minimum height on these two widgets,
            // and it should be scrollable if necessary:
            Expanded(
              child: Placeholder(),
            ),
            Expanded(
              child: Placeholder(),
            )
          ],
        ),
      ),
    );
  }
}

Run Code Online (Sandbox Code Playgroud)

Rus*_*mov 8

这对我有用:

import 'dart:math'; // for max function

// Add the following around your column
LayoutBuilder(
  builder: (BuildContext context, BoxConstraints constraints) {
    return SingleChildScrollView(
      child: ConstrainedBox(
        constraints: BoxConstraints.tightFor(height: max(500, constraints.maxHeight)),
        child: Column(), // your column
      ),
    );
  },
);
Run Code Online (Sandbox Code Playgroud)

替换500为您想要的柱的最小高度。