Last active
March 6, 2020 14:40
-
-
Save jddeep/a71747cfd7affd83480448922e3beb4b to your computer and use it in GitHub Desktop.
fluttery-bubbles
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 'package:flutter/material.dart'; | |
import 'dart:math'; | |
class FlutterBubble { | |
static final _rng = Random(); | |
double size; | |
Color color; | |
Alignment alignment; | |
FlutterBubble() { | |
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: FlutterBubbles(50), | |
), | |
), | |
), | |
), | |
); | |
} | |
class FlutterBubbles extends StatefulWidget { | |
final _flutterbubbles; | |
FlutterBubbles(this._flutterbubbles); | |
@override | |
_FlutterBubblesState createState() => _FlutterBubblesState(); | |
} | |
class _FlutterBubblesState extends State<FlutterBubbles> { | |
final _bubbles = <FlutterBubble>[]; | |
@override | |
void initState() { | |
super.initState(); | |
_genFlutterBubbles(); | |
} | |
void _genFlutterBubbles() { | |
_bubbles.clear(); | |
for (int i = 0; i < widget._flutterbubbles; i++) { | |
_bubbles.add(FlutterBubble()); | |
} | |
} | |
bool isNight = true; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: isNight ? Colors.black : Colors.white, | |
appBar: AppBar(title: Center(child: Text('Tap your Flutter bubble'))), | |
body: GestureDetector( | |
onTap: () => setState(() { | |
isNight = !isNight; | |
_genFlutterBubbles(); | |
}), | |
child: Stack( | |
children: [ | |
for (final bubble in _bubbles) | |
Positioned.fill( | |
child: AnimatedAlign( | |
duration: Duration(milliseconds: 500), | |
curve: Curves.easeInOut, | |
alignment: bubble.alignment, | |
child: AnimatedContainer( | |
duration: Duration(milliseconds: 500), | |
decoration: BoxDecoration( | |
color: bubble.color, | |
shape: BoxShape.circle, | |
), | |
child: Padding( | |
padding: EdgeInsets.all(8.0), | |
child: FlutterLogo( | |
colors: Colors.blue, | |
size: 5, | |
), | |
), | |
height: bubble.size, | |
width: bubble.size, | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment