Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created April 21, 2021 10:37
Show Gist options
  • Save pingbird/d0fca7e7fcb6b55d905a12a2bf90b861 to your computer and use it in GitHub Desktop.
Save pingbird/d0fca7e7fcb6b55d905a12a2bf90b861 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage>
with SingleTickerProviderStateMixin {
AnimationController _controller;
void start() async {
var position = 0;
while (mounted) {
position++;
_controller.animateTo(
position.toDouble(),
curve: Curves.ease,
duration: const Duration(milliseconds: 200),
);
await Future.delayed(const Duration(seconds: 1));
}
}
@override
void initState() {
super.initState();
_controller = AnimationController.unbounded(vsync: this);
start();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: AnimatedBuilder(
animation: _controller,
builder: (_, child) {
return Transform.rotate(
angle: _controller.value * (math.pi / 8),
child: child,
);
},
child: Container(height: 200, width: 200, color: Colors.orangeAccent),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment