Skip to content

Instantly share code, notes, and snippets.

@cristianfb1989
Created March 3, 2020 16:40
Show Gist options
  • Save cristianfb1989/3eea933d9d612bb5db3aa87a67aab86a to your computer and use it in GitHub Desktop.
Save cristianfb1989/3eea933d9d612bb5db3aa87a67aab86a to your computer and use it in GitHub Desktop.
import 'dart:ui';
import 'package:flutter/material.dart';
class SpinKitRotatingPlain extends StatefulWidget {
final Color color;
final double size;
final IndexedWidgetBuilder itemBuilder;
final Duration duration;
final AnimationController controller;
SpinKitRotatingPlain({
Key key,
this.color,
this.size = 100,
this.itemBuilder,
this.duration = const Duration(seconds: 2),
this.controller,
}) : assert(
!(itemBuilder is IndexedWidgetBuilder && color is Color) &&
!(itemBuilder == null && color == null),
'You should specify either a itemBuilder or a color'),
assert(size != null),
super(key: key);
@override
_SpinKitRotatingPlainState createState() => _SpinKitRotatingPlainState();
}
class _SpinKitRotatingPlainState extends State<SpinKitRotatingPlain>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _animation1, _animation2;
@override
void initState() {
super.initState();
_controller = (widget.controller ??
AnimationController(vsync: this, duration: widget.duration))
..addListener(() => setState(() {}))
..repeat();
_animation1 = Tween(begin: 0.0, end: 180.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.easeIn)));
_animation2 = Tween(begin: 0.0, end: 180.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.5, 1.0, curve: Curves.easeInOut)));
}
@override
void dispose() {
super.dispose();
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final double valorAngulo = 0.0174533;
double sizeContainerBlur = 100;
double sizeSigma = 2;
return Stack(
children: <Widget>[
Align(
child: Center(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: sizeSigma, sigmaY: sizeSigma),
child: Container(
width: sizeContainerBlur,
height: sizeContainerBlur,
child: Container(color: Colors.black.withOpacity(0)),
),
),
),
),
Center(
child: Transform(
transform: Matrix4.identity()
..rotateX((0 - _animation1.value) * valorAngulo)
..rotateY((0 - _animation2.value) * valorAngulo),
alignment: FractionalOffset.center,
child: SizedBox.fromSize(
size: Size.square(widget.size),
child: Container(
child: Image.asset(
'images/logo_google.png',
height: 90,
width: 90,
alignment: Alignment.center,
))),
),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment