Last active
December 7, 2022 21:10
-
-
Save HansMuller/18a4e56a1f32a520640d21f09c287d01 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'; | |
class Home extends StatefulWidget { | |
const Home({ super.key }); | |
@override | |
State<Home> createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> with SingleTickerProviderStateMixin { | |
double currentOpacity = 1.0; | |
double targetOpacity = 1.0; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: TweenAnimationBuilder<double>( | |
tween: Tween<double>(begin: currentOpacity, end: targetOpacity), | |
duration: Duration(milliseconds: 400), | |
builder: (BuildContext context, double opacity, Widget? child) { | |
currentOpacity = opacity; | |
return Opacity( | |
opacity: opacity, | |
child: child, | |
); | |
}, | |
child: ElevatedButton( | |
onPressed: () { | |
setState(() { targetOpacity -= 0.2; }); | |
}, | |
child: Text('Press Me'), | |
), | |
), | |
), | |
); | |
} | |
} | |
void main() { | |
runApp( | |
MaterialApp( | |
theme: ThemeData.light(useMaterial3: true), | |
home: Home(), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment