Created
June 17, 2020 17:34
-
-
Save cshannon3/a0793ed2a84c27d6140da0dbfa01f12c to your computer and use it in GitHub Desktop.
test
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'; | |
import 'dart:math'; | |
class DiscData { | |
static final _rng = Random(); | |
double size; | |
Color color; | |
Alignment alignment; | |
DiscData() { | |
color = Color.fromARGB( | |
_rng.nextInt(200), | |
_rng.nextInt(255), | |
_rng.nextInt(255), | |
_rng.nextInt(255), | |
); | |
size = _rng.nextDouble() * 40 + 10; | |
alignment = Alignment( | |
_rng.nextDouble() * 2 - 1, | |
_rng.nextDouble() * 2 - 1, | |
); | |
} | |
} | |
void main() async { | |
runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Container( | |
color: Color(0xFF15202D), | |
child: SizedBox.expand( | |
child: VariousDiscs(50), | |
), | |
), | |
), | |
), | |
); | |
} | |
class VariousDiscs extends StatefulWidget { | |
final numberOfDiscs; | |
VariousDiscs(this.numberOfDiscs); | |
@override | |
_VariousDiscsState createState() => _VariousDiscsState(); | |
} | |
class _VariousDiscsState extends State<VariousDiscs> { | |
final _discs = <DiscData>[]; | |
@override | |
void initState() { | |
super.initState(); | |
_makeDiscs(); | |
} | |
void _makeDiscs() { | |
_discs.clear(); | |
for (int i = 0; i < widget.numberOfDiscs; i++) { | |
_discs.add(DiscData()); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return GestureDetector( | |
onTap: () => setState(() { | |
_makeDiscs(); | |
}), | |
child: Stack( | |
children: [ | |
Center( | |
child: Text( | |
'Click a disc!', | |
style: TextStyle(color: Colors.white, fontSize: 50), | |
), | |
), | |
for (final disc in _discs) | |
Positioned.fill( | |
child: AnimatedAlign( | |
duration: Duration(milliseconds: 500), | |
curve: Curves.easeInOut, | |
alignment: disc.alignment, | |
child: AnimatedContainer( | |
duration: Duration(milliseconds: 500), | |
decoration: BoxDecoration( | |
color: disc.color, | |
shape: BoxShape.circle, | |
), | |
height: disc.size, | |
width: disc.size, | |
), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment