Bottom Sheets
Loading preview
Starting the Flutter app
Simple, form, draggable, and nested scrolling variants
import 'package:flutter/material.dart';
class BottomSheets extends StatelessWidget {
const BottomSheets({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Bottom Sheets')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
ListTile(
title: const Text('Simple Sheet'),
subtitle: const Text('Basic modal bottom sheet'),
onTap: () => _showSimpleSheet(context),
),
ListTile(
title: const Text('Form Sheet'),
subtitle: const Text('Sheet with input fields'),
onTap: () => _showFormSheet(context),
),
ListTile(
title: const Text('Draggable Sheet'),
subtitle: const Text('Sheet with drag handle'),
onTap: () => _showDraggableSheet(context),
),
],
),
);
}
void _showSimpleSheet(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (ctx) => Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Simple Bottom Sheet',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
const Text('This is a basic modal bottom sheet.'),
const SizedBox(height: 24),
FilledButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Close'),
),
],
),
),
);
}
void _showFormSheet(BuildContext context) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (ctx) => Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(ctx).viewInsets.bottom,
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Form Sheet',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 16),
TextField(
decoration: const InputDecoration(
labelText: 'Name',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
TextField(
decoration: const InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 24),
FilledButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Submit'),
),
],
),
),
),
);
}
void _showDraggableSheet(BuildContext context) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (ctx) => DraggableScrollableSheet(
initialChildSize: 0.5,
minChildSize: 0.25,
maxChildSize: 0.9,
expand: false,
builder: (ctx, controller) => ListView(
controller: controller,
padding: const EdgeInsets.all(24),
children: [
Center(
child: Container(
width: 40,
height: 4,
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.outline,
borderRadius: BorderRadius.circular(2),
),
),
),
Text(
'Draggable Sheet',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 8),
const Text(
'Drag the handle to resize. This sheet supports nested scrolling.'),
for (var i = 1; i <= 8; i++)
ListTile(
leading: CircleAvatar(child: Text('$i')),
title: Text('Item $i'),
),
],
),
),
);
}
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
Three private helpers wrap showModalBottomSheet. _showFormSheet sets isScrollControlled and pads by viewInsets.bottom so fields clear the keyboard. _showDraggableSheet passes the DraggableScrollableSheet controller to its ListView, letting scroll and resize cooperate, with expand: false so it sizes inside the modal. The form’s TextFields have no controllers, so Submit only closes the sheet.
Adapting it
- Add controllers in
_showFormSheet, and return values throughNavigator.pop(ctx, data). - Tune
initialChildSize,minChildSizeandmaxChildSizefor your content. - Pass
showDragHandle: truetoshowModalBottomSheetin place of the hand-drawn handle.