Skip to content

Instantly share code, notes, and snippets.

@Piinks
Created October 22, 2025 23:08
Show Gist options
  • Select an option

  • Save Piinks/8e51856dbecb8ad2dda43ee2dbe5b8bc to your computer and use it in GitHub Desktop.

Select an option

Save Piinks/8e51856dbecb8ad2dda43ee2dbe5b8bc to your computer and use it in GitHub Desktop.
Playing with draggable scrollable sheet
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
/// Flutter code sample for [DraggableScrollableSheet].
void main() => runApp(const DraggableScrollableSheetExampleApp());
class DraggableScrollableSheetExampleApp extends StatelessWidget {
const DraggableScrollableSheetExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
scrollBehavior: MaterialScrollBehavior().copyWith(dragDevices: PointerDeviceKind.values.toSet()),
theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue.shade100)),
home: Scaffold(
appBar: AppBar(title: const Text('DraggableScrollableSheet Sample')),
body: const DraggableScrollableSheetExample(),
),
);
}
}
class DraggableScrollableSheetExample extends StatefulWidget {
const DraggableScrollableSheetExample({super.key});
@override
State<DraggableScrollableSheetExample> createState() => _DraggableScrollableSheetExampleState();
}
class _DraggableScrollableSheetExampleState extends State<DraggableScrollableSheetExample> {
double _sheetPosition = 0.5;
final double _dragSensitivity = 600;
@override
Widget build(BuildContext context) {
final ColorScheme colorScheme = Theme.of(context).colorScheme;
return DraggableScrollableSheet(
initialChildSize: _sheetPosition,
builder: (BuildContext context, ScrollController scrollController) {
return ColoredBox(
color: colorScheme.primary,
child: Column(
children: <Widget>[
// Header wrapper with gesture?
Container(height: 50, color: Colors.green),
Flexible(
child: ListView.builder(
controller: scrollController,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('Item $index', style: TextStyle(color: colorScheme.surface)),
);
},
),
),
],
),
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment