Created
March 30, 2019 20:41
-
-
Save chrislentz/b7832457e60595d9d56ba760b928418f to your computer and use it in GitHub Desktop.
This is the full code sample used in my "Flutter Draggable" example on Instagram.
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(ExampleApp()); | |
class ExampleApp extends StatelessWidget { | |
final Widget icon = Icon(Icons.sentiment_very_satisfied, size: 100.0); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
Draggable<String>( | |
data: "face", | |
child: icon, | |
childWhenDragging: Opacity( | |
opacity: 0.5, | |
child: icon, | |
), | |
feedback: RotationTransition( | |
turns: AlwaysStoppedAnimation(15 / 360), | |
child: icon, | |
), | |
), | |
Container( | |
width: 100.0, | |
height: 100.0, | |
color: Color(0xff8fc3ff), | |
child: DragTarget<String>( | |
builder: (context, candidateData, rejectedData) { | |
return Container(); | |
}, | |
onWillAccept: (data) { | |
if (data == "face") { | |
print('Will be accepted.'); | |
return true; | |
} else { | |
print('Will be rejected.'); | |
return false; | |
} | |
}, | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment