A draggable dialog helper for Flutter.
Features
- Drag a dialog by its title. The dialog stays on screen.
- Replace the header, body, and footer.
- Theme the dialog with
DraggableDialogThemeData, including as aThemeExtension.
Add the package
Add this dependency to pubspec.yaml:
dependencies:
legacy_draggable_dialog: ^0.2.0
Show a dialog
Call showLegacyDraggableDialog. The title is the drag handle. onClose adds a close button. Dragging that button does not move the dialog.
showLegacyDraggableDialog(
context: context,
title: 'Details',
body: const Text('Hello World'),
onClose: () => Navigator.of(context).pop(),
);
To hide the header, set showHeader to false. To let the body scroll itself, set scrollable to false. To resize from the footer, set resizable to true.
Theme one app
Set DraggableDialogThemeData on ThemeData.extensions. DraggableDialogThemeData.from reads that extension. Fields you leave null keep the built-in light and dark colors.
MaterialApp(
theme: ThemeData(
extensions: const [
DraggableDialogThemeData(headerColor: Colors.indigo),
],
),
);
You can still pass theme on one call. Older arguments such as buttonColor and headerHeight still override theme. Set those fields on DraggableDialogThemeData instead.
For a fully custom shell, call showDraggableDialogWithBuilder and pass onDragUpdate to the widget that should drag. The route stores position in pixels so drag speed stays 1:1 with the pointer. Custom chrome can read ResizeHandleProvider for left and right resize handles and to report a content-height ceiling. Set intrinsicHeight when the dialog should size to its child until the first resize.