import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
void main() {
runApp(MaterialApp(home: const ScheduleBindingScreen()));
}
class ScheduleBindingScreen extends StatefulWidget {
const ScheduleBindingScreen({super.key});
@override
State<ScheduleBindingScreen> createState() => _ScheduleBindingScreenState();
}
class _ScheduleBindingScreenState extends State<ScheduleBindingScreen> with SingleTickerProviderStateMixin {
double angle = 0.0;
late final AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(vsync: this, duration: Duration(seconds: 1))..addListener(() {setState(() {angle += 0.1;});});
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
void _start() {
controller.forward();
}
void _reverse() {
controller.reverse();
}
@override
Widget build(BuildContext context) {
final screen = Scaffold(
appBar: AppBar(title: Text('ScheduleBindingTets'),),
body: SafeArea(child: Center(child: Transform.rotate(angle: angle, child: Container(width: 100, height: 100, color: Colors.blue,),),),),
floatingActionButton: FloatingActionButton(onPressed: () {
if(controller.isCompleted) {
_reverse();
} else {
_start();
}
},
child: controller.isCompleted ? Icon(Icons.rotate_left_rounded) : Icon(Icons.play_arrow)
),
);
return screen;
}
}
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme