Fadein and Fadeout using AnimatedOpacity Widget in Flutter

This Article is posted by seven.srikanth at 14-03-2019 05:01:07

In this article, I'm going to share you the example of how to Fadein and Fadeout using AnimatedOpactiy Widget.
Here is how the final output is going to look.
Below is an example code of how to Fadein and Fadeout using AnimatedOpcity widget in Flutter. This Code from Main.dart file. In order to run this project locally, all you need to do is to create a Project and copy paste the below code to Lib\main.dart file.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _visible = true;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "AnimatedOpacity Example",
home: Scaffold(
appBar: AppBar(title: Text('AnimatedOpacity Example'),),
body: MyHomePage(visible: _visible),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.flip),
onPressed: (){
setState(() {
_visible = !_visible;
});
},
),
),
);
}
}
class MyHomePage extends StatefulWidget {
final bool visible;
const MyHomePage({Key key, this.visible}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Center(
child: AnimatedOpacity(
child: Container(
child: Center(child: Text('Hello World')),
width: 200.0,
height: 200.0,
color: Colors.green,
), duration: Duration(seconds: 1),
opacity: widget.visible ? 1.0: 0.0,
),
);
}
}
Hope this will be helpful to you.
Thanks,
Srikanth

Tags: Fadein and Fadeout using AnimatedOpacity Widget; Animation examples;



0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.



Recent Articles


How to deploy flutter web site on GitHub using peanut

Posted by nikhilchaudhary12155 on 13 Oct 2019 Article


AnimatedPositioned Widget Example in Flutter

Posted by seven.srikanth on 10 Oct 2019 Article


Flutter Open-Source and directory lists

Posted by nishantkotatech on 09 Oct 2019 Article


Flutter Travelling Couple Leading Page - Flutter Web Series 3

Posted by nikhilchaudhary12155 on 05 Oct 2019 Article



© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com