gg_map_animation 0.9.0 copy "gg_map_animation: ^0.9.0" to clipboard
gg_map_animation: ^0.9.0 copied to clipboard

By adding a .map method to Animation, GgMapAnimationExtension allows you to map one Animation easily to another.

example/lib/main.dart

// @license
// Copyright (c) 2019 - 2021 Dr. Gabriel Gatzsche. All Rights Reserved.
//
// Use of this source code is governed by terms that can be
// found in the LICENSE file in the root of this package.

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:gg_map_animation/gg_map_animation.dart';

// #############################################################################
void main() {
  runApp(MyApp());
}

// #############################################################################
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'GgMapAnimationExample',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: GgMapAnimationExample(),
    );
  }
}

// #############################################################################
class GgMapAnimationExample extends StatefulWidget {
  GgMapAnimationExample({Key? key}) : super(key: key);

  @override
  _GgMapAnimationExampleState createState() => _GgMapAnimationExampleState();
}

// #############################################################################
class _GgMapAnimationExampleState extends State<GgMapAnimationExample>
    with TickerProviderStateMixin {
  // ...........................................................................
  @override
  void initState() {
    _animation =
        AnimationController(vsync: this, duration: Duration(seconds: 3));

    // ...........................................................
    // Create a mapped animation which maps the value of the input
    // animation to an angle
    _mappedAnimation = _animation.map((inVal) => 2 * pi * inVal);
    super.initState();
  }

  // ...........................................................................
  void _buttonPressed() {
    if (_animation.status == AnimationStatus.forward ||
        _animation.status == AnimationStatus.completed) {
      _animation.reverse();
    } else {
      _animation.forward();
    }
  }

  // ...........................................................................
  late AnimationController _animation;
  late Animation<double> _mappedAnimation;

  // ...........................................................................
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('GgMapAnimationExample'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            // Animate using the mapped animation
            AnimatedBuilder(
                animation: _mappedAnimation,
                child: Container(
                  width: 100,
                  height: 100,
                  color: Colors.blue,
                ),
                builder: (context, child) {
                  return Transform.rotate(
                      angle: _mappedAnimation.value, child: child);
                })
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _buttonPressed,
        tooltip: 'Go',
        child: Icon(Icons.rotate_left_outlined),
      ),
    );
  }
}
0
likes
120
pub points
31%
popularity

Publisher

unverified uploader

By adding a .map method to Animation, GgMapAnimationExtension allows you to map one Animation easily to another.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on gg_map_animation