Created
June 14, 2021 06:31
-
-
Save Rahiche/6943a8e1a9ae2a0539edfa7884225372 to your computer and use it in GitHub Desktop.
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(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
static const String _title = 'Flutter Code Sample'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: _title, | |
home: Scaffold( | |
appBar: AppBar(title: const Text(_title)), | |
body: const MyStatefulWidget(), | |
), | |
); | |
} | |
} | |
class MyStatefulWidget extends StatefulWidget { | |
const MyStatefulWidget({Key? key}) : super(key: key); | |
@override | |
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); | |
} | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> { | |
double top = 0; | |
double left = 0; | |
@override | |
Widget build(BuildContext context) { | |
final child = Material( | |
child: Container( | |
height: 100.0, | |
width: 100.0, | |
color: Colors.red, | |
child: const Center( | |
child: Text('Draggable'), | |
), | |
), | |
); | |
return Stack( | |
children: <Widget>[ | |
Positioned( | |
top: top, | |
left: left, | |
child: Draggable<int>( | |
data: 10, | |
onDragUpdate: (details) { | |
top = top + details.delta.dy; | |
left = left + details.delta.dx; | |
setState(() {}); | |
}, | |
child: child, | |
feedback: child, | |
), | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment