Bottom Sheet
Bottom Sheet
▲▼▲▼▲▼
tags : #coding #flutter
references : Widget
▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼
▲▼▲▼▲▼
Example Code
Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
showBottomSheet(
context: context,
builder: (context) {
return Container(
height: 200,
color: Colors.white,
child: Center(child: Text("Persistent Bottom Sheet")),
);
},
);
},
child: Icon(Icons.add),
),
);
Key Points:
Example Code
Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
height: 300,
padding: EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text("Modal Bottom Sheet", style: TextStyle(fontSize: 18,
fontWeight: FontWeight.bold)),
SizedBox(height: 10),
Text("This bottom sheet will close when you tap outside."),
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text("Close"),
),
],
),
);
},
);
},
child: Icon(Icons.menu),
),
);
Key Points:
Example Code
Scaffold(
body: Stack(
children: [
Center(child: Text("Main Content")),
DraggableScrollableSheet(
initialChildSize: 0.3, // 30% of screen height
minChildSize: 0.1, // Minimum height (10%)
maxChildSize: 0.9, // Maximum height (90%)
builder: (context, scrollController) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
child: ListView.builder(
controller: scrollController,
itemCount: 20,
itemBuilder: (context, index) {
return ListTile(title: Text("Item $index"));
},
),
);
},
),
],
),
);
Key Points:
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
child: ...
);
showModalBottomSheet(
context: context,
isScrollControlled: true, // Makes it full screen
builder: (context) => Container(
height: MediaQuery.of(context).size.height, // Full height
child: Center(child: Text("Full Screen Bottom Sheet")),
),
);
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => Padding(
padding: EdgeInsets.only(bottom:
MediaQuery.of(context).viewInsets.bottom),
child: TextField(decoration: InputDecoration(hintText: "Type here...")),
),
);
Final Thoughts
Bottom Sheets in Flutter are powerful UI components for displaying quick actions, options, or
additional information without interrupting user flow. Choosing the right type—persistent, modal,
or draggable—depends on your use case. With proper customization, you can create sleek and
intuitive bottom sheets for a great user experience! 🚀
Would you like an advanced example or a specific implementation for your projects?