Skip to content

Instantly share code, notes, and snippets.

@monkeyswarm
Created July 19, 2021 22:15
Show Gist options
  • Save monkeyswarm/363c70ea89e1704a2547e482c9a05c97 to your computer and use it in GitHub Desktop.
Save monkeyswarm/363c70ea89e1704a2547e482c9a05c97 to your computer and use it in GitHub Desktop.
Drag from bottom sheet to body target
import 'package:flutter/material.dart';
void main() {
runApp(HomePage());
}
class HomePage extends StatelessWidget {
static const double dim = 50;
final _scaffoldKey = GlobalKey<ScaffoldState>();
HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
key: _scaffoldKey,
floatingActionButton: FloatingActionButton(
onPressed: () {
_scaffoldKey.currentState!.showBottomSheet((context) {
return Container(
height: 200,
color: Colors.lightGreen,
child: Center(
child: Draggable<int>(
data: 1,
onDragStarted: () => Future.delayed(
Duration(seconds: 1),
() => Navigator.pop(context)),
feedback: Container(
width: dim,
height: dim,
color: Colors.greenAccent),
child: Container(
width: dim,
height: dim,
color: Colors.grey,
child: Text('Draggable!')))));
});
},
),
body: Center(
child: DragTarget<int>(
builder: (context, candidateData, _) => Container(
width: dim * 2,
height: dim * 2,
color: candidateData.isNotEmpty
? Colors.redAccent
: Colors.lightBlue,
child: Text('DragTarget!')),
onWillAccept: (_) => true,
onAccept: (_) => true))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment