Created
September 13, 2021 05:58
-
-
Save red-star25/d9b9c4dd269075872fde30d3410da965 to your computer and use it in GitHub Desktop.
This file contains 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 '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