Skip to content

Instantly share code, notes, and snippets.

@monkeyswarm
Created July 22, 2021 19:10
Show Gist options
  • Save monkeyswarm/58a143bfee818f3d8318de75d3f679e9 to your computer and use it in GitHub Desktop.
Save monkeyswarm/58a143bfee818f3d8318de75d3f679e9 to your computer and use it in GitHub Desktop.
DraggableScrollableSheet with header leaves a shade
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final _scaffoldKey = GlobalKey<ScaffoldState>();
void _showSheet() => _scaffoldKey.currentState!.showBottomSheet((context) =>
DraggableScrollableSheet(
expand: false,
builder: (BuildContext context, ScrollController scrollController) =>
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: 80,
color: Colors.grey,
child: Center(child: Text('Drag me down from top'))),
Flexible(
child: Container(
color: Colors.blue[100],
child: ListView.builder(
controller: scrollController,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(title: Text('Item $index'));
},
)))
],
)));
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
key: _scaffoldKey,
floatingActionButton: FloatingActionButton(onPressed: _showSheet),
body: Align(
alignment: Alignment.topCenter,
child: ElevatedButton(
onPressed: () {},
child: Text('I am a button, but am I under a shade?'))),
),
);
}
}
@Nikzed
Copy link

Nikzed commented Mar 17, 2022

thank you! ❤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment