Commit 773d6731 by Rizal Hermawan

feat (init): Migrating package flutter_sequence_animation to null safetty

parents
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: b1395592de68cc8ac4522094ae59956dd21a91db
channel: stable
project_type: package
## [0.0.1] - TODO: Add release date.
* TODO: Describe initial release.
TODO: Add your license here.
# flutter_sequence_animation_null_safety
A new Flutter package project.
## Getting Started
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
library flutter_sequence_animation_null_safety;
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
class _AnimationInformation {
_AnimationInformation({
this.animatable,
this.from,
this.to,
this.curve,
this.tag,
});
final Animatable? animatable;
final Duration? from;
final Duration? to;
final Curve? curve;
final Object? tag;
}
class SequenceAnimationBuilder {
List<_AnimationInformation> _animations = [];
/// Adds an [Animatable] to the sequence, in the most cases this would be a [Tween].
/// The from and to [Duration] specify points in time where the animation takes place.
/// You can also specify a [Curve] for the [Animatable].
///
/// [Animatable]s which animate on the same tag are not allowed to overlap and they also need to be add in the same order they are played.
/// These restrictions only apply to [Animatable]s operating on the same tag.
///
///
/// ## Sample code
///
/// ```dart
/// SequenceAnimation sequenceAnimation = new SequenceAnimationBuilder()
/// .addAnimatable(
/// animatable: new ColorTween(begin: Colors.red, end: Colors.yellow),
/// from: const Duration(seconds: 0),
/// to: const Duration(seconds: 2),
/// tag: "color",
/// )
/// .animate(controller);
/// ```
///
SequenceAnimationBuilder addAnimatable({
@required Animatable? animatable,
@required Duration? from,
@required Duration? to,
Curve curve: Curves.linear,
@required Object? tag,
}) {
assert(to! >= from!);
_animations.add(new _AnimationInformation(
animatable: animatable!, from: from!, to: to!, curve: curve, tag: tag!));
return this;
}
/// The controllers duration is going to be overwritten by this class, you should not specify it on your own
SequenceAnimation animate(AnimationController? controller) {
int longestTimeMicro = 0;
_animations.forEach((info) {
int micro = info.to!.inMicroseconds;
if (micro > longestTimeMicro) {
longestTimeMicro = micro;
}
});
// Sets the duration of the controller
controller!.duration = new Duration(microseconds: longestTimeMicro);
Map<Object, Animatable> animatables = {};
Map<Object, double> begins = {};
Map<Object, double> ends = {};
_animations.forEach((info) {
assert(info.to!.inMicroseconds <= longestTimeMicro);
double begin = info.from!.inMicroseconds / longestTimeMicro;
double end = info.to!.inMicroseconds / longestTimeMicro;
Interval intervalCurve = new Interval(begin, end, curve: info.curve!);
if (animatables[info.tag] == null) {
animatables[info.tag!] =
IntervalAnimatable.chainCurve(info.animatable!, intervalCurve);
begins[info.tag!] = begin;
ends[info.tag!] = end;
} else {
assert(
(ends[info.tag!])! <= begin,
"When animating the same property you need to: \n"
"a) Have them not overlap \n"
"b) Add them in an ordered fashion");
animatables[info.tag!] = IntervalAnimatable(
animatable: animatables[info.tag!],
defaultAnimatable:
IntervalAnimatable.chainCurve(info.animatable!, intervalCurve),
begin: begins[info.tag],
end: ends[info.tag],
);
ends[info.tag!] = end;
}
});
Map<Object, Animation> result = {};
animatables.forEach((tag, animInfo) {
result[tag] = animInfo.animate(controller);
});
return new SequenceAnimation._internal(result);
}
}
class SequenceAnimation {
final Map<Object, Animation>? _animations;
/// Use the [SequenceAnimationBuilder] to construct this class.
SequenceAnimation._internal(this._animations);
/// Returns the animation with a given tag, this animation is tied to the controller.
Animation? operator [](Object key) {
assert(_animations!.containsKey(key),
"There was no animatable with the key: $key");
return _animations![key];
}
}
/// Evaluates [animatable] if the animation is in the time-frame of [begin] (inclusive) and [end] (inclusive),
/// if not it evaluates the [defaultAnimatable]
class IntervalAnimatable<T> extends Animatable<T> {
IntervalAnimatable({
@required this.animatable,
@required this.defaultAnimatable,
@required this.begin,
@required this.end,
});
final Animatable? animatable;
final Animatable? defaultAnimatable;
/// The relative begin to of [animatable]
/// If your [AnimationController] is running from 0->1, this needs to be a value between those two
final double? begin;
/// The relative end to of [animatable]
/// If your [AnimationController] is running from 0->1, this needs to be a value between those two
final double? end;
/// Chains an [Animatable] with a [CurveTween] and the given [Interval].
/// Basically, the animation is being constrained to the given interval
static Animatable chainCurve(Animatable parent, Interval interval) {
return parent.chain(new CurveTween(curve: interval));
}
@override
T transform(double t) {
if (t >= begin! && t <= end!) {
return animatable!.transform(t);
} else {
return defaultAnimatable!.transform(t);
}
}
}
\ No newline at end of file
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
name: flutter_sequence_animation_null_safety
description: Composite together any animation with this robust and simple to use package.
version: 3.0.1
author: Norbert Kozsir <kozsir.norbert@gmail.com>
homepage: https://github.com/Norbert515/flutter_sequence_animation
environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
import 'package:flutter_test/flutter_test.dart';
void main() {
test('adds one to input values', () {
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment