0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AnimationControllerを使った直線的なアニメーションの実装

0
Posted at
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;
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?