Last active
December 31, 2019 20:35
-
-
Save Adem68/53f23e776663f1caac2747f276cb00ee 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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'MAI New Year 2020', | |
theme: ThemeData( | |
textTheme: TextTheme( | |
body1: TextStyle(color: Colors.white), | |
)), | |
home: Tree(), | |
); | |
} | |
} | |
class Tree extends StatelessWidget { | |
static final List<double> _offsets = | |
_generateOffsets(100, 0.05).toList(growable: false); | |
@override | |
Widget build(BuildContext context) { | |
return Material( | |
color: Colors.black, | |
child: Align( | |
child: Container( | |
constraints: BoxConstraints(maxWidth: 500), | |
child: ListView( | |
children: <Widget>[ | |
Center(child: Icon(Icons.star, color: Colors.yellow)), | |
SizedBox(height: 10), | |
for (final x in _offsets) Light(x), | |
SizedBox(height: 50), | |
Center(child: Text('Mutlu Yıllar from MAI.')) | |
], | |
padding: const EdgeInsets.symmetric(vertical: 50, horizontal: 10), | |
), | |
), | |
), | |
); | |
} | |
static Iterable<double> _generateOffsets( | |
int count, double acceleration) sync* { | |
double x = 0; | |
yield x; | |
double ax = acceleration; | |
for (var i = 0; i < count; i++) { | |
x += ax; | |
ax *= 1.5; | |
final maxLateral = min(1, i / count); | |
if (x.abs() > maxLateral) { | |
x = maxLateral * x.sign; | |
ax = x >= 0 ? -acceleration : acceleration; | |
} | |
yield x; | |
} | |
} | |
} | |
class Light extends StatefulWidget { | |
static List<Color> festiveColors = [ | |
Colors.green, | |
Colors.red, | |
Colors.orange, | |
]; | |
final double x; | |
final int period; | |
final Color color; | |
Light(this.x, {Key key}) | |
: period = 500 + (x.abs() * 2000).floor(), | |
color = festiveColors[(x.abs() * 42).floor() % festiveColors.length], | |
super(key: key); | |
@override | |
_LightState createState() => _LightState(); | |
} | |
class _LightState extends State<Light> { | |
Color _newColor = Colors.white; | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
height: 10, | |
child: Align( | |
alignment: Alignment(widget.x, 0), | |
child: AspectRatio( | |
aspectRatio: 1, | |
child: TweenAnimationBuilder( | |
tween: ColorTween(begin: widget.color, end: _newColor), | |
duration: Duration(milliseconds: widget.period), | |
onEnd: () { | |
setState(() { | |
_newColor = | |
_newColor == Colors.white ? widget.color : Colors.white; | |
}); | |
}, | |
builder: (_, color, __) => Container(color: color), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment