Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Created February 13, 2023 04:37
Show Gist options
  • Save ponnamkarthik/f5a0cb9f3686bd659c93825fcc85d46a to your computer and use it in GitHub Desktop.
Save ponnamkarthik/f5a0cb9f3686bd659c93825fcc85d46a to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App',
theme: ThemeData(
colorSchemeSeed: Colors.indigo,
useMaterial3: true,
brightness: Brightness.light,
),
darkTheme: ThemeData(
colorSchemeSeed: Colors.blue,
useMaterial3: true,
brightness: Brightness.dark,
),
home: const HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double buttonXPos = 0;
double buttonYPos = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
AnimatedPositioned(
duration: const Duration(milliseconds: 0),
top: buttonYPos,
left: buttonXPos,
child: Draggable(
childWhenDragging: SizedBox(),
child: Container(
width: 100,
height: 40,
color: Colors.red,
),
feedback: Container(
width: 100,
height: 40,
color: Colors.red,
),
onDragUpdate: (DragUpdateDetails details) {
setState(() {
buttonXPos = details.globalPosition.dx;
buttonYPos = details.globalPosition.dy;
});
},
onDragEnd:(DraggableDetails details) {
setState(() {
buttonXPos = details.offset.dx;
buttonYPos = details.offset.dy;
});
},
)
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment