Skip to content

Instantly share code, notes, and snippets.

@TramPamPam
Last active August 18, 2023 14:13
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 TramPamPam/5951d7517c3328918ee34f565d428a3b to your computer and use it in GitHub Desktop.
Save TramPamPam/5951d7517c3328918ee34f565d428a3b to your computer and use it in GitHub Desktop.
Bounce
import 'package:flutter/material.dart';
import 'dart:math' as math;
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: Scaffold(
body: Center(
child: Animated(child: YourWidget())
),
),
);
}
}
class Animated extends StatefulWidget {
const Animated({Key? key, required this.child}) : super(key: key);
final Widget child;
@override
State<Animated> createState() => _AnimatedState();
}
class _AnimatedState extends State<Animated>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
void initState() {
super.initState();
/// paste controller here:
_controller = AnimationController(
duration: Duration(seconds: 2),
vsync: this,
)..repeat();
}
@override
Widget build(BuildContext context) {
/// paste builder here:
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Transform.rotate(
angle: _controller.value * 2 * math.pi,
child: ScaleTransition(
scale: Tween<double>(begin: 0.8, end: 1.2).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
),
child: child,
),
);
},
child: widget.child,
);
}
}
class YourWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 66,
width: 66,
clipBehavior: Clip.antiAlias,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Color(0xFFB5B6C2),
),
child: const Center(child: Text('Vibrant')),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment