Skip to content

Instantly share code, notes, and snippets.

@nick45chen
Last active February 16, 2023 15:14
Show Gist options
  • Save nick45chen/810896d72765464fbfc8a4179b1be96c to your computer and use it in GitHub Desktop.
Save nick45chen/810896d72765464fbfc8a4179b1be96c to your computer and use it in GitHub Desktop.
text fade-in animation
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: const Scaffold(
body: Center(
child: MyHomePage(),
),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 800),
)..forward();
late final Animation<Offset> _slideAnimation = Tween<Offset>(
begin: const Offset(0, -0.5),
end: Offset.zero,
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut));
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SlideTransition(
position: _slideAnimation,
child: FadeTransition(
opacity: _controller,
child: Text('Hello World', style: textStyle),
),
)),
);
}
TextStyle? get textStyle => Theme.of(context).textTheme.headlineMedium;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment