-
-
Save mkiisoft/7330d12b2b770b4dc256d45ea207386c to your computer and use it in GitHub Desktop.
just need random color package
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:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:random_color/random_color.dart'; | |
class SlowScrollView extends StatefulWidget { | |
@override | |
_SlowScrollViewState createState() => _SlowScrollViewState(); | |
} | |
class _SlowScrollViewState extends State<SlowScrollView> | |
with SingleTickerProviderStateMixin { | |
RandomColor _randomColor = RandomColor(); | |
Timer _timer; | |
double _top = -150; | |
int _count = 100; | |
int _cross = 50; | |
List<List<Color>> _colors = []; | |
final w = 150.0; | |
final h = 250.0; | |
final _spacing = 10.0; | |
@override | |
void initState() { | |
_setUp(); | |
_timer = Timer.periodic( | |
Duration(milliseconds: 200), | |
(_) { | |
if (mounted) | |
setState(() { | |
_top -= 1; | |
if (_top == (h + (_spacing * 2)) * _count) { | |
_setUp(add: 100); | |
} | |
}); | |
}, | |
); | |
super.initState(); | |
} | |
void _setUp({int add = 0}) { | |
for (int c = 0; c < _cross; c++) { | |
_colors.add([]); | |
for (int i = 0; i < (_count + add); i++) { | |
_colors[c].add(_randomColor.randomColor()); | |
} | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Stack( | |
children: <Widget>[ | |
for (int i = 0; i < _cross; i++) | |
..._buildColumn(i, (i * w) + _spacing), | |
], | |
), | |
); | |
} | |
List<Widget> _buildColumn(int c, double left) { | |
final _children = <Widget>[]; | |
double _offsetX = 0; | |
double _offsetY = 0; | |
if (c.isOdd) { | |
_offsetX = h / 2; | |
} | |
_offsetY = 0 - w / 2; | |
for (int i = 0; i < _count; i++) { | |
_children.add(AnimatedPositioned( | |
top: _offsetX + (_top + (i * h)), | |
left: _offsetY + left, | |
duration: Duration(milliseconds: 50), | |
child: Container( | |
width: w - _spacing, | |
height: h - _spacing, | |
color: _colors[c][i], | |
), | |
)); | |
} | |
return _children; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment