我不知道如何在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(),
)
],
),
),
);
}
}
答案 0 :(得分:2)
这对我有用:
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
替换为所需的列的最小高度。
答案 1 :(得分:0)
改用Flexible
double height = MediaQuery.of(context).size.height;
Container(
height:height
child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Flexible(
child:Container()
),
Container(
height:200
)
])
)