Skip to content

Instantly share code, notes, and snippets.

@funwithflutter
Last active August 10, 2021 21:05
Show Gist options
  • Select an option

  • Save funwithflutter/e10fcbfdaf6d4b030d2e5486e62d16a6 to your computer and use it in GitHub Desktop.

Select an option

Save funwithflutter/e10fcbfdaf6d4b030d2e5486e62d16a6 to your computer and use it in GitHub Desktop.
Flutter AnimatedBuilder example
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Animation Course',
home: Scaffold(
appBar: AppBar(
title: const Text('Explicit Animations'),
),
body: const Center(
child: AnimatedBuilderExample(),
),
),
);
}
}
class AnimatedBuilderExample extends StatefulWidget {
const AnimatedBuilderExample({Key? key}) : super(key: key);
@override
_AnimatedBuilderExampleState createState() => _AnimatedBuilderExampleState();
}
class _AnimatedBuilderExampleState extends State<AnimatedBuilderExample>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: const Duration(seconds: 10));
_controller.repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Transform.rotate(
angle: _controller.value * 2 * pi,
child: child,
);
},
child: Container(color: Colors.red, width: 100, height: 100),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment