我不知道如何在 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(),
)
],
),
),
);
}
}
最佳答案
这对我有用:
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
),
);
},
);
替换
500
具有您想要的列的最小高度。
关于Flutter:最小高度,扩展和 SingleChildScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58582611/