Skip to content

Instantly share code, notes, and snippets.

@md-weber
Created December 29, 2021 19:23
Show Gist options
  • Save md-weber/4662ffc22883537ae91888366241eeb0 to your computer and use it in GitHub Desktop.
Save md-weber/4662ffc22883537ae91888366241eeb0 to your computer and use it in GitHub Desktop.
Basic Animation for a Short
import 'package:flutter/material.dart';
class BorderAnimationRound extends StatefulWidget {
const BorderAnimationRound({Key? key}) : super(key: key);
@override
_BorderAnimationRoundState createState() => _BorderAnimationRoundState();
}
class _BorderAnimationRoundState extends State<BorderAnimationRound>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: const Duration(seconds: 1));
_controller
..forward()
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
_controller.forward(from: 0);
}
})
..addListener(() {
setState(() {});
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 150,
height: 50,
decoration: BoxDecoration(
boxShadow: const [
BoxShadow(
offset: Offset(1, 1),
blurRadius: 3,
color: Colors.black,
)
],
gradient: SweepGradient(
startAngle: 4,
colors: const [Colors.black, Colors.blue],
transform: GradientRotation(_controller.value * 6),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: const BoxDecoration(
color: Colors.white,
),
alignment: Alignment.center,
child: const Text("Hello"),
),
)),
),
);
}
}
//try it on dartpad -> https://dartpad.dev/?id=c10652caa336d17362394623d0c0028e
import 'package:flutter/material.dart';
class BorderAnimationRound extends StatefulWidget {
const BorderAnimationRound({Key? key}) : super(key: key);
@override
_BorderAnimationRoundState createState() => _BorderAnimationRoundState();
}
class _BorderAnimationRoundState extends State<BorderAnimationRound>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: const Duration(seconds: 1));
_controller
..forward()
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
_controller.forward(from: 0);
}
})
..addListener(() {
setState(() {});
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: SweepGradient(
startAngle: 3,
colors: const [Colors.black, Colors.blue],
transform: GradientRotation(_controller.value * 6),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
alignment: Alignment.center,
child: const Text("Hello"),
),
),
),
),
);
}
}
void main() async {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
color: const Color(0xFF15202D),
child: const SizedBox.expand(
child: BorderAnimationRound(),
),
),
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment