Last active
December 31, 2020 15:19
-
-
Save Adem68/2734793a827699d191662c47413d11c7 to your computer and use it in GitHub Desktop.
Mutlu Yıllar. Adem
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 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Mutlu Yıllar', | |
theme: ThemeData( | |
textTheme: TextTheme( | |
bodyText2: 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. Adem Furkan ÖZCAN')) | |
], | |
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