Skip to content

Instantly share code, notes, and snippets.

@jaumard
Created July 8, 2020 11:34
Show Gist options
  • Save jaumard/137c665415b15004876e70d156a4fc37 to your computer and use it in GitHub Desktop.
Save jaumard/137c665415b15004876e70d156a4fc37 to your computer and use it in GitHub Desktop.
Basic rotation animation with Hooks
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends HookWidget {
@override
Widget build(BuildContext context) {
final controller = useAnimationController(duration: Duration(milliseconds: 800));
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
RotationTransition(
turns: controller,
child: ColoredBox(
color: Colors.red,
child: SizedBox(
width: 200,
height: 200,
),
),
),
FlatButton(
onPressed: () {
if (controller.isCompleted) {
controller.reset();
}
controller.animateTo(controller.value + .25);
},
child: Text(
'Rotate',
style: TextStyle(color: Colors.red),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment