Skip to content

Instantly share code, notes, and snippets.

@scottbaggett
Created April 16, 2019 06:17
Show Gist options
  • Save scottbaggett/f461db36d9d09820a684e4a7658ecd9a to your computer and use it in GitHub Desktop.
Save scottbaggett/f461db36d9d09820a684e4a7658ecd9a to your computer and use it in GitHub Desktop.
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