This post focuses on a super secret Flutter project I designed for desktop and web that uses a canvas and draggable node interface. This tutorial will show how I use stacks to accomplish draggable functionality with widgets. As shown below. We will dynamically add items to the stack and to distinguish them, I will use the RandomColor typer. So we have to add that package.
We can then create the HomeView that contains our stack class HomeView extends StatefulWidget { @override _HomeViewState createState() => _HomeViewState(); } class _HomeViewState extends State<HomeView> { List<Widget> movableItems = []; @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: movableItems, )); } } The functionality is very simple. We will have a class _MoveableStackItemState extends State<MoveableStackItem> { double xPosition = 0; double yPosition = 0; Color color; @override void initState() { color = RandomColor().randomColor(); super.initState(); } @override Widget build(BuildContext context) { return Positioned( top: yPosition, left: xPosition, child: GestureDetector( onPanUpdate: (tapInfo) { setState(() { xPosition += tapInfo.delta.dx; yPosition += tapInfo.delta.dy; }); }, child:Container( width: 150, height: 150, color: color, ), ), ); } } The last thing to do is to add a new return Scaffold( floatingActionButton:FloatingActionButton( onPressed: () { setState(() { movableItems.add(MoveableStackItem()); }); }, ), body: Stack( children: movableItems, )); That's it. Now you have a movable Stack on your view. This is the end of this article about creating a movable stack widget in flutter. For more related flutter stack widget content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: In-depth explanation of Mysql deadlock viewing and deadlock removal
>>: Detailed explanation of mysql deadlock checking and deadlock removal examples
This article example shares the specific code of ...
Recently, I need to use a lot of fragmented pictu...
Recently, I need to query all the fields in a rel...
1. Some problems encountered I remember when we w...
There is another tree structure Javascript object...
Method 1: Use the SET PASSWORD command First log ...
In Nginx, there are some advanced scenarios where...
1. Command Introduction nl (Number of Lines) adds...
1. Connect Centos7 under VMware and set a fixed I...
Repetition: Repeat certain page design styles thr...
This article shares the specific code of JavaScri...
question The tomcat container was successfully ad...
Study plans are easily interrupted and difficult ...
time(); function Function prototype: time_t time(...
This article shares the specific code of js to ac...