Skip to content

Instantly share code, notes, and snippets.

@shivanchalaeologic
Last active August 2, 2020 05:35
Show Gist options
  • Select an option

  • Save shivanchalaeologic/c7b234e156a81d50db37994a519b77ae to your computer and use it in GitHub Desktop.

Select an option

Save shivanchalaeologic/c7b234e156a81d50db37994a519b77ae to your computer and use it in GitHub Desktop.
import 'package:dough/dough.dart';
import 'package:flutter/material.dart';
class DraggableDoughDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
// This is the widget that appears before being dragged around.
final myDraggableChild = Container(
width: 100,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.blue,
),
child: Center(
child: Text(
'Draggable',
textAlign: TextAlign.center,
style: Theme.of(context).accentTextTheme.bodyText2,
),
),
);
// This is the widget that gets dragged around.
final myFeedbackWidget = Container(
width: 100,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.green,
),
child: Center(
child: Text(
'Drag Me ',
textAlign: TextAlign.center,
style: Theme.of(context).accentTextTheme.bodyText2,
),
),
);
myDraggableDough() => DoughRecipe(
data: DoughRecipeData(
adhesion: 4,
viscosity: 500,
draggablePrefs: DraggableDoughPrefs(
breakDistance: 80,
useHapticsOnBreak: true,
),
),
child: DraggableDough<String>(
data: 'My data!',
child: myDraggableChild,
feedback: myFeedbackWidget,
onDoughBreak: () {},
),
);
myDragTarget() => DragTarget<String>(
builder: (context, candidateData, rejectedData) {
return Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color:
candidateData.length > 0 ? Colors.lightGreen : Colors.grey,
),
child: Center(
child: Text(
'Drag target',
textAlign: TextAlign.center,
style: Theme.of(context).accentTextTheme.bodyText2,
),
),
);
},
onWillAccept: (value) => value == 'My data!',
onAccept: (value) {},
);
return Scaffold(
appBar: AppBar(
title: Text('Draggable Dough'),
),
body: Stack(
children: [
Positioned(
left: 50,
top: 50,
child: myDraggableDough(),
),
Positioned(
right: 50,
bottom: 50,
child: myDragTarget(),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment