Created
April 16, 2019 06:17
-
-
Save scottbaggett/f461db36d9d09820a684e4a7658ecd9a to your computer and use it in GitHub Desktop.
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:developer'; | |
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
class FadeInOnScroll extends StatefulWidget { | |
final ScrollController controller; | |
final double offset; | |
final Widget child; | |
final int duration; | |
const FadeInOnScroll( | |
{Key key, | |
@required this.child, | |
@required this.offset, | |
@required this.duration, | |
@required this.controller}) | |
: super(key: key); | |
@override | |
_FadeInOnScrollState createState() => _FadeInOnScrollState(); | |
} | |
class _FadeInOnScrollState extends State<FadeInOnScroll> { | |
_FadeInOnScrollState(); | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedBuilder( | |
animation: widget.controller, | |
child: widget.child, | |
builder: (BuildContext context, Widget child) { | |
double _opacityLevel = | |
(widget.controller.offset > widget.offset) ? 1.0 : 0.0; | |
return AnimatedOpacity( | |
duration: Duration( | |
milliseconds: (widget.duration != null) ? widget.duration : 200), | |
opacity: _opacityLevel, | |
child: child, | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment