Created
January 6, 2023 22:38
-
-
Save xster/866af18d02458258b02ae40dbc0652d2 to your computer and use it in GitHub Desktop.
Draggable bottom sheet repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const BottomSheetApp()); | |
class BottomSheetApp extends StatelessWidget { | |
const BottomSheetApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: const Text('Bottom Sheet Sample')), | |
body: const BottomSheetExample(), | |
), | |
); | |
} | |
} | |
class BottomSheetExample extends StatelessWidget { | |
const BottomSheetExample({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: ElevatedButton( | |
child: const Text('showModalBottomSheet'), | |
onPressed: () => showModalBottomSheet( | |
context: context, | |
isScrollControlled: true, | |
isDismissible: true, | |
shape: const RoundedRectangleBorder( | |
borderRadius: BorderRadius.vertical(top: Radius.circular(15)), | |
), | |
builder: (context) => DraggableScrollableSheet( | |
initialChildSize: 0.4, | |
minChildSize: 0.2, | |
maxChildSize: 0.9, | |
expand: false, | |
builder: (context, scrollController) => SafeArea( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
Container( | |
height: 50, | |
color: Colors.red, | |
child: const Center( | |
child: Text('This cannot be dragged up'), | |
), | |
), | |
Expanded( | |
child: ListView.builder( | |
controller: scrollController, | |
itemCount: 100, | |
itemBuilder: (context, index) => ListTile( | |
title: Text('This can be dragged $index'), | |
onTap: () => Navigator.of(context).pop(index), | |
), | |
), | |
), | |
], | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment