Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created March 21, 2020 21:03
Show Gist options
  • Save graphicbeacon/e1582dff8384c7aa6ffea7640d7b8db2 to your computer and use it in GitHub Desktop.
Save graphicbeacon/e1582dff8384c7aa6ffea7640d7b8db2 to your computer and use it in GitHub Desktop.

Revisions

  1. graphicbeacon created this gist Mar 21, 2020.
    78 changes: 78 additions & 0 deletions main.dart
    Original 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())
    )
    )
    )
    ]
    );
    }
    }