• Stars
    star
    294
  • Rank 141,303 (Top 3 %)
  • Language
    Dart
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Widgets for creating Hero-like animations between two widgets within the same screen.

flutter_sidekick

Widgets for creating Hero-like animations between two widgets within the same screen.

Pub Donate

Logo

Overview

Features

  • Hero-like animations.
  • Allow you to specify a different animation for each Sidekick.
  • Widget to manage animations between children of two multi-child widgets.

Getting started

In the pubspec.yaml of your flutter project, add the following dependency: The latest version is Pub

dependencies:
  ...
  flutter_sidekick: ^latest_version

In your library add the following import:

import 'package:flutter_sidekick/flutter_sidekick.dart';

For help getting started with Flutter, view the online documentation.

Widgets

Sidekick

The Sidekick widget is heavily inspired by the Hero widget API. To link two sidekicks, the targetTag property of the one denoted as the source must be identical to the tag property of the other one, denoted the target. Then to animate sidekicks, you can use the SidekickController and one of the move function.

The animation below can be created with the following code:

Simple Overview

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

class SimpleExample extends StatefulWidget {
  @override
  _SimpleExampleState createState() => _SimpleExampleState();
}

class _SimpleExampleState extends State<SimpleExample>
    with TickerProviderStateMixin {
  SidekickController controller;

  @override
  void initState() {
    super.initState();
    controller =
        SidekickController(vsync: this, duration: Duration(seconds: 1));
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Positioned(
          top: 20.0,
          left: 20.0,
          width: 100.0,
          height: 100.0,
          child: GestureDetector(
            onTap: () => controller.moveToTarget(context),
            child: Sidekick(
              tag: 'source',
              targetTag: 'target',
              child: Container(
                color: Colors.blue,
              ),
            ),
          ),
        ),
        Positioned(
          bottom: 20.0,
          right: 20.0,
          width: 150.0,
          height: 100.0,
          child: GestureDetector(
            onTap: () => controller.moveToSource(context),
            child: Sidekick(
              tag: 'target',
              child: Container(
                color: Colors.blue,
              ),
            ),
          ),
        ),
      ],
    );
  }
}

SidekickTeamBuilder

The SidekickTeamBuilder widget can be used to create complex layouts, where widgets from one container can be moved to another one, and you want the transition to be animated:

Wrap Overview

import 'package:example/widgets/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_sidekick/flutter_sidekick.dart';

class Item {
  Item({
    this.id,
  });
  final int id;
}

class WrapExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SidekickTeamBuilder<Item>(
      initialSourceList: List.generate(20, (i) => Item(id: i)),
      builder: (context, sourceBuilderDelegates, targetBuilderDelegates) {
        return Padding(
          padding: const EdgeInsets.all(8.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              SizedBox(
                height: 120.0,
                child: Wrap(
                  children: sourceBuilderDelegates
                      .map((builderDelegate) => builderDelegate.build(
                            context,
                            WrapItem(builderDelegate.message, true),
                            animationBuilder: (animation) => CurvedAnimation(
                                  parent: animation,
                                  curve: Curves.ease,
                                ),
                          ))
                      .toList(),
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    CircleButton(
                      text: '>',
                      onPressed: () => SidekickTeamBuilder.of<Item>(context)
                          .moveAll(SidekickFlightDirection.toTarget),
                    ),
                    SizedBox(width: 60.0, height: 60.0),
                    CircleButton(
                      text: '<',
                      onPressed: () => SidekickTeamBuilder.of<Item>(context)
                          .moveAll(SidekickFlightDirection.toSource),
                    ),
                  ],
                ),
              ),
              SizedBox(
                height: 250.0,
                child: Wrap(
                  children: targetBuilderDelegates
                      .map((builderDelegate) => builderDelegate.build(
                            context,
                            WrapItem(builderDelegate.message, false),
                            animationBuilder: (animation) => CurvedAnimation(
                                  parent: animation,
                                  curve: FlippedCurve(Curves.ease),
                                ),
                          ))
                      .toList(),
                ),
              )
            ],
          ),
        );
      },
    );
  }
}

class WrapItem extends StatelessWidget {
  const WrapItem(
    this.item,
    this.isSource,
  ) : size = isSource ? 40.0 : 50.0;
  final bool isSource;
  final double size;
  final Item item;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => SidekickTeamBuilder.of<Item>(context).move(item),
      child: Padding(
        padding: const EdgeInsets.all(2.0),
        child: Container(
          height: size - 4,
          width: size - 4,
          color: _getColor(item.id),
        ),
      ),
    );
  }

  Color _getColor(int index) {
    switch (index % 4) {
      case 0:
        return Colors.blue;
      case 1:
        return Colors.green;
      case 2:
        return Colors.yellow;
      case 3:
        return Colors.red;
    }
    return Colors.indigo;
  }
}

Changelog

Please see the Changelog page to know what's recently changed.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a new feature, please send a pull request.

More Repositories

1

flutter_staggered_grid_view

A Flutter staggered grid view
Dart
3,043
star
2

flutter_slidable

A Flutter implementation of slidable list item with directional slide actions.
Dart
2,695
star
3

flutter_sticky_header

Flutter implementation of sticky headers for sliver
Dart
880
star
4

local_hero

A widget which implicitly launches a hero animation when its position changed within the same route.
Dart
204
star
5

gap

Flutter widgets for easily adding gaps inside Flex widgets such as Columns and Rows or scrolling views
Dart
193
star
6

binder

A lightweight, yet powerful way to bind your application state with your business logic.
Dart
177
star
7

flutter_counter_challenge_2020

A set of counter apps made for #FlutterCounterChallenge2020
Dart
174
star
8

overflow_view

A widget displaying children in a line until there is not enough space and showing a the number of children not rendered.
Dart
170
star
9

nil

A simple Flutter widget to add in the widget tree when you want to show nothing, with minimal impact on performance.
Dart
152
star
10

RestLess

The automatic type-safe-reflectionless REST API client library for .Net Standard
C#
110
star
11

flutter_parallax

A Flutter widget that moves according to a scroll controller.
Dart
100
star
12

flutter_scatter

A widget that displays a collection of dispersed and non-overlapping children
Dart
91
star
13

visual_effect

VisualEffect API for Flutter
Dart
70
star
14

polygon

A simple way to draw polygon shapes and to clip them
Dart
62
star
15

maestro

A way to compose your app's state and to expose your data across your entire Flutter application.
Dart
47
star
16

atomized_image

A widget which paints and animates images with particles to achieve an atomized effect
Dart
40
star
17

hashwag

Flutter app that showcases some hashtags
Dart
25
star
18

value_layout_builder

A LayoutBuilder with an extra value
Dart
17
star
19

state_watcher

A simple, yet powerful reactive state management solution for Flutter applications
Dart
15
star
20

DoLess.UriTemplates

.Net Standard implementation of the URI Template Spec https://tools.ietf.org/html/rfc6570
C#
14
star
21

flutter-binder-snippets

Quick and easy Binder snippets
13
star
22

flutter_puzzle_hack

Dart
10
star
23

dash_punk

Dart
6
star
24

letsar

My profile
5
star
25

DoLess.Commands

Commands for Mvvm
C#
4
star
26

DoLess.Bindings

C#
3
star
27

DoLess.Localization

A simple way to share localization files (resx) from cross-platform lib to iOS and Android libs
C#
3
star
28

letsar.github.io

JavaScript
2
star
29

RestLess.JsonNet

Json formatters for RestLess using Json.Net
C#
1
star
30

adventofcode_2021

Dart
1
star