Created
September 6, 2023 08:23
-
-
Save IslamRustamov/a1adcf0d1df2375d7d8af4216cdbeb8a to your computer and use it in GitHub Desktop.
This file contains 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 'dart:math'; | |
import 'package:flutter/material.dart'; | |
import 'package:statsfl/statsfl.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return StatsFl( | |
isEnabled: true, | |
align: Alignment.center, | |
child: const MaterialApp( | |
home: MyHomePage(), | |
), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Stack(children: [ | |
...List<RotatedSquare>.generate( | |
3000, | |
(i) => const RotatedSquare(), | |
), | |
const Center( | |
child: const Image( | |
width: 300, | |
height: 300, | |
image: AssetImage('assets/photo.png'), | |
), | |
), | |
])); | |
} | |
} | |
class RotatedSquare extends StatefulWidget { | |
const RotatedSquare({super.key}); | |
@override | |
State<RotatedSquare> createState() => _RotatedSquareState(); | |
} | |
class _RotatedSquareState extends State<RotatedSquare> | |
with SingleTickerProviderStateMixin { | |
late AnimationController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = AnimationController( | |
duration: const Duration(milliseconds: 2000), | |
vsync: this, | |
) | |
..forward() | |
..addListener(() { | |
if (controller.isCompleted) { | |
controller.repeat(); | |
} | |
}); | |
} | |
@override | |
void dispose() { | |
controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
double width = MediaQuery.of(context).size.width; | |
double height = MediaQuery.of(context).size.height; | |
return Positioned( | |
top: Random().nextDouble() * (height - 20), | |
left: Random().nextDouble() * (width - 20), | |
child: RotationTransition( | |
turns: Tween(begin: 0.0, end: 1.0).animate(controller), | |
child: Container( | |
height: 20, | |
width: 20, | |
color: Colors.purple, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment