Skip to content

Instantly share code, notes, and snippets.

@HansMuller
Last active December 7, 2022 21:10
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 HansMuller/18a4e56a1f32a520640d21f09c287d01 to your computer and use it in GitHub Desktop.
Save HansMuller/18a4e56a1f32a520640d21f09c287d01 to your computer and use it in GitHub Desktop.
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