Created
July 19, 2021 22:15
-
-
Save monkeyswarm/363c70ea89e1704a2547e482c9a05c97 to your computer and use it in GitHub Desktop.
Drag from bottom sheet to body target
This file contains hidden or 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(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