Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square circle #61

Merged
merged 2 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ For more info, please, refer to the `showcase.dart` in the example.
<br />
</td>
<td align="center">
<img src="https://raw.githubusercontent.com/abhishek0706/flutter_spinkit/square_circle/screenshots/square_circle.gif" width="100px">
<br />
SquareCircle
<br />
</td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions lib/flutter_spinkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export 'src/ripple.dart';
export 'src/rotating_circle.dart';
export 'src/rotating_plain.dart';
export 'src/spinning_circle.dart';
export 'src/square_circle.dart';
export 'src/three_bounce.dart';
export 'src/wandering_cubes.dart';
export 'src/wave.dart';
103 changes: 103 additions & 0 deletions lib/src/square_circle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'dart:math' as math;
import 'package:flutter/widgets.dart';

class SpinKitSquareCircle extends StatefulWidget {
// ignore: prefer_const_constructors_in_immutables
SpinKitSquareCircle({
Key key,
this.color,
this.size = 50.0,
this.itemBuilder,
this.duration = const Duration(seconds: 1),
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);

final Color color;
final double size;
final IndexedWidgetBuilder itemBuilder;
final Duration duration;
final AnimationController controller;

@override
_SpinKitSquareCircleState createState() => _SpinKitSquareCircleState();
}

class _SpinKitSquareCircleState extends State<SpinKitSquareCircle>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation_curve;
Animation<double> animation_size;

@override
void initState() {
super.initState();
controller =
AnimationController(vsync: this, duration: Duration(milliseconds: 500));

animation_curve = Tween(begin: 1.0, end: 0.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeInOutCubic,
),
);
animation_curve.addListener(() => setState(() {}));

animation_size = Tween(begin: 0.5, end: 1.0).animate(
CurvedAnimation(
parent: controller,
curve: Curves.easeInOutCubic,
),
);
animation_size.addListener(() => setState(() {}));

controller.forward();

controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
controller.reverse();
} else if (status == AnimationStatus.dismissed) {
controller.forward();
}
});
}

@override
void dispose() {
controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
final Matrix4 transform = Matrix4.identity();
transform.rotateZ(animation_curve.value * math.pi);
return Center(
child: Transform(
transform: transform,
alignment: FractionalOffset.center,
child: _itembuilder(0),
),
);
}

Widget _itembuilder(int index) {
final double currentSize = widget.size * animation_size.value;
return widget.itemBuilder != null
? widget.itemBuilder(context, index)
: Container(
height: currentSize,
width: currentSize,
decoration: BoxDecoration(
color: widget.color,
borderRadius: BorderRadius.all(
Radius.circular(0.5 * currentSize * animation_curve.value),
),
),
);
}
}
Binary file added screenshots/square_circle.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.