Consider the following example:
import 'package:flutter/material.dart';
void main() {
const project = MaterialApp(
home: HomeScreen(),
);
runApp(project);
}
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Widget bottomSheetView() {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 128,
height: 128,
color: Colors.black,
),
Container(
width: 128,
height: 128,
color: Colors.black,
),
Container(
width: 128,
height: 128,
color: Colors.black,
),
/* ... */
],
);
}
void gotoBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return bottomSheetView();
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('HomeScreen'),
),
body: SafeArea(
child: Center(
child: ElevatedButton(
onPressed: () => gotoBottomSheet(),
child: const Text('BottomSheet'),
),
),
),
);
}
}
If you keep adding containers, eventually you will reach a RenderFlex overflow error because the bottom sheet has a height limit by default.
How can I remove such a limit so that the column that takes minimum size can grow a bit more?
This is just a verbose paragraph because it seems to be the unfortunate case that StackOverflow does not like issues whose main content is mostly code.
2
Answers
Easiest way to do is that wrap your
Column
of bottomSheetView method withSingleChildScrollView
like belowAnd In your
goToBottomSheet
method addisScrollControlled: true
like belowWrap the bottomSheet widget in the Container widget because every widget takes the height of the parent widget and Container has 0 height & 0 width by default.
And In your goToBottomSheet method add