Filter by Widgets


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
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

Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Check out this article on Error: The name 'RangeSlider' is defined in the libraries 'package:flutter/src/material/range_slider.dart' and 'package:flutter_range_slider/src/flutter_range_slider.dart'.

Read full post

How to create a persistent bottom sheet in Flutter?

Check out this article on How to create a persistent bottom sheet in Flutter?

Read full post

How to draw a Decorative Horizontal line in Flutter?

Check out this article on How to draw a Decorative Horizontal line in Flutter?

Read full post

How to fetch an Image from Internet in Flutter

Check out this article on How to fetch an Image from Internet in Flutter

Read full post

ListView with Images from the Internet

Check out this article on ListView with Images from the Internet

Read full post

How to show Tooltip in Flutter?

Check out this article on How to show Tooltip in Flutter?

Read full post

How to create BottomNavigationBar in flutter?

Check out this article on How to create BottomNavigationBar in flutter?

Read full post

How to add actions to Appbar?

Check out this article on How to add actions to Appbar?

Read full post

How to open dart devtools in VS code?

Check out this article on How to open dart devtools in VS code?

Read full post

Accessibility features in flutter

Check out this article on Accessibility features in flutter

Read full post

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

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License , and code samples are licensed under the BSD License.