Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created September 13, 2021 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/d9b9c4dd269075872fde30d3410da965 to your computer and use it in GitHub Desktop.
Save red-star25/d9b9c4dd269075872fde30d3410da965 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget>
with SingleTickerProviderStateMixin {
late final AnimationController controller = AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this,
);
late final Animation<double> animation = CurvedAnimation(
parent: controller,
curve: Curves.easeIn,
);
@override
void initState() {
super.initState();
animation.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed) {
controller.reverse();
} else if (status == AnimationStatus.dismissed) {
controller.forward();
}
});
controller.forward();
}
@override
Widget build(BuildContext context) {
return CustomScrollView(slivers: <Widget>[
SliverFadeTransition(
opacity: animation,
sliver: SliverToBoxAdapter(
child: Center(
child: Image.network(
"https://1gew6o3qn6vx9kp3s42ge0y1-wpengine.netdna-ssl.com/wp-content/uploads/prod/2020/10/HERO-ART-microsoft_azure_1920x1000_nologo.jpg",
width: double.infinity,
height: 300,
fit: BoxFit.cover,
),
),
))
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment