Skip to content

Instantly share code, notes, and snippets.

@olumidayy
Last active January 17, 2021 17:24
Show Gist options
  • Save olumidayy/2ce7f6c0783b6b7d6c49b14f3aaf8ad3 to your computer and use it in GitHub Desktop.
Save olumidayy/2ce7f6c0783b6b7d6c49b14f3aaf8ad3 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget>
with TickerProviderStateMixin {
AnimationController _controller;
Animation<double> _animation;
var opacityLevel = 0.0;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 1500),
vsync: this,
);
_animation = CurvedAnimation(
parent: _controller,
curve: Curves.linear,
);
Future.delayed(Duration(seconds: 1), () {
setState(() {
_controller.forward();
opacityLevel = 1;
});
});
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Container(width: 50, height: 50, color: Colors.blue),
AnimatedOpacity(
child: SizeTransition(
sizeFactor: _animation,
axis: Axis.horizontal,
axisAlignment: -1,
child: Center(
child: FlutterLogo(size: 200.0),
),
),
opacity: opacityLevel,
duration: Duration(seconds: 2))
])),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment