I can't figure out how to do this layout in Flutter. What I'm trying to achieve is:
I hope that makes sense - I have no idea how to implement this. I've tried lots of combinations of Expanded, Flexible, Column, SingleChildScrollView, min column axis size etc. but everything I try results in some kind of infinite height exception. Is this even possible?
Here's some example code: the following works fine. How to implement scroll and minimum height on the two placeholders?
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(),
)
],
),
),
);
}
}
Are you trying to set minimum or maximum height or width of Container() widget in a Flutter, then use ' constraints ' attribute and apply BoxConstraints() on it like below.
A box in which a single widget can be scrolled. This widget is useful when you have a single box that will normally be entirely visible, for example a clock face in a time picker, but you need to make sure it can be scrolled if the container gets too small in one axis (the scroll direction).
This has worked for me:
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
),
);
},
);
Replace 500
with the minimum height you want for the Column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With