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
Table of contents 1. What is recursion? 2. Solve ...
XHTML defines three document type declarations. T...
This article shares the installation and configur...
This article describes the commonly used MySQL fu...
Problems: After adding the -v parameter to docker...
Table of contents Business Background Using Techn...
Table of contents 1 Introduction to user variable...
Installing Electron cnpm install electron -g Inst...
The installation tutorial of mysql 5.7.19 winx64 ...
Table of contents 1. The role of nginx process lo...
Table of contents 1. Rule 1: Object.Method() 1.1 ...
Preface When creating a primary and foreign key f...
When associating two tables, a foreign key could ...
Table of contents 1. Check whether the docker env...
We all know that Apache can easily set rewrites f...