Created
March 21, 2020 21:03
-
-
Save graphicbeacon/e1582dff8384c7aa6ffea7640d7b8db2 to your computer and use it in GitHub Desktop.
Revisions
-
graphicbeacon created this gist
Mar 21, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ import 'package:flutter/material.dart'; void main() => runApp(MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Page() ) )); class Page extends StatefulWidget { @override PageState createState() => PageState(); } class PageState extends State<Page> { double left = 0; double leftStart; final double startW = 100; double initW = 100; double containerWidth = 100; @override Widget build(BuildContext context) { return Stack( children: <Widget>[ Positioned( left: left, child: GestureDetector( onHorizontalDragStart: (details) { setState(() { leftStart = details.globalPosition.dx; }); }, onHorizontalDragUpdate: (details) { var offsetWidth = details.globalPosition.dx - leftStart; var updatedWidth = (offsetWidth + initW).roundToDouble(); var screenWidth = MediaQuery.of(context).size.width; setState(() { if (updatedWidth < startW) { containerWidth = startW; return; } if (updatedWidth > screenWidth) { containerWidth = screenWidth; return; } containerWidth = updatedWidth; }); }, onHorizontalDragEnd: (details) { setState(() { initW = containerWidth.roundToDouble(); }); }, child: Container( width: containerWidth, height: MediaQuery.of(context).size.height, color: Colors.purple, child: Text(containerWidth.toString()) ) ) ) ] ); } }