Skip to content

Instantly share code, notes, and snippets.

@guid-empty
Last active April 8, 2021 13:55
Show Gist options
  • Save guid-empty/f829d4b8eb8dea5ee93fe3e6f824d692 to your computer and use it in GitHub Desktop.
Save guid-empty/f829d4b8eb8dea5ee93fe3e6f824d692 to your computer and use it in GitHub Desktop.
Implicit Amimations - AnimatedOpacity
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class OtusLogo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Image.network('https://github.com/flutter-cats/otus-cocktails-application/blob/master/logo-2.8602b.svg'),
width: 200.0,
height: 200.0,
color: Colors.green,
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _transparent = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Implicit Amimations - AnimatedOpacity'),
),
body: Center(
child: AnimatedOpacity(
opacity: _transparent ? 0.0 : 1.0,
duration: const Duration(seconds: 1),
child: OtusLogo(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_transparent = !_transparent;
});
},
child: Icon(Icons.opacity),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment