Last active
November 24, 2020 10:22
-
-
Save agreensh/8a736979bcd1249bb21f998ef51014ca to your computer and use it in GitHub Desktop.
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 characters
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| // This widget is the root of your application. | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| debugShowCheckedModeBanner: false, | |
| theme: ThemeData( | |
| primaryColor: const Color(0xFF02BB9F), | |
| primaryColorDark: const Color(0xFF167F67), | |
| accentColor: const Color(0xFF02BB9F), | |
| ), | |
| home: MyHomePage(title: 'Flutter Clip Path'), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| MyHomePage({Key key, this.title}) : super(key: key); | |
| final String title; | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| final double widthHeight = 100.0; | |
| final double step = 2.0; | |
| var leftPos = 0.0; | |
| var topPos = 0.0; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| leftPos = -widthHeight; | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Stack( | |
| children: [ | |
| AnimatedPositioned( | |
| onEnd: () { | |
| setState(() { | |
| leftPos += step; | |
| if (leftPos > MediaQuery.of(context).size.width - widthHeight / 2) { | |
| leftPos = 0.0; | |
| topPos += widthHeight; | |
| } else if (topPos > MediaQuery.of(context).size.height - widthHeight / 2) { | |
| leftPos = 0.0; | |
| topPos = 0.0; | |
| } | |
| }); | |
| }, | |
| top: topPos, | |
| left: leftPos, | |
| child: Container(width: widthHeight, height: widthHeight, color: Colors.red), | |
| duration: Duration(milliseconds: 20), | |
| ), | |
| ], | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| child: Icon(Icons.add), | |
| onPressed: () { | |
| setState(() { | |
| leftPos += step; | |
| }); | |
| }, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment