Skip to content

Commit

Permalink
feat!: remove AnimatableState(Mixin)? (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed May 29, 2023
1 parent fe20ceb commit 6996c59
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 132 deletions.
4 changes: 2 additions & 2 deletions melos.yaml
Expand Up @@ -20,10 +20,10 @@ scripts:
run: daco format --set-exit-if-changed .

analyze:
exec: dart analyze
exec: dart analyze --fatal-infos

analyze:doc_comments:
exec: daco analyze
exec: daco analyze --fatal-infos

test:unit:
exec: flutter test
Expand Down
27 changes: 12 additions & 15 deletions packages/fleet/README.md
Expand Up @@ -11,8 +11,7 @@
state change. No need to manage `AnimationController`s or `Tween`s.
- **Animatable widgets**: Comes out of the box with general purpose widgets that
support animating with Fleet.
- [**Extensible**][animatablestatemixin]: Any widget can be made to support
animating with Fleet.
- **Extensible**: Any widget can be made to support animating with Fleet.
- **Flexible**: Animatable widgets can be used with or without animations.
- **Composable**: Widgets that build on animatable widgets are automatically
animatable.
Expand Down Expand Up @@ -89,7 +88,7 @@ Now lets animate the state change of `_active`:
});
},
- child: ColoredBox(
+ child: AColoredBox(
+ child: FleetColoredBox(
color: _active ? Colors.blue : Colors.grey,
),
);
Expand All @@ -103,23 +102,23 @@ We made the following changes:
`setStateWithAnimation`.
2. Use `setStateWithAnimation` to specify the animation that we want to apply to
the state change.
3. Use `AColoredBox` instead of `ColoredBox`.
3. Use `FleetColoredBox` instead of `ColoredBox`.

The `AColoredBox` widget is a drop-in replacement for `ColoredBox` that supports
animating with Fleet. Widgets that support animating with Fleet don't have any
special parameters related to animation and can be used without animation, just
as well.
The `FleetColoredBox` widget is a drop-in replacement for `ColoredBox` that
supports animating with Fleet. Widgets that support animating with Fleet don't
have any special parameters related to animation and can be used without
animation, just as well.

Fleet provides drop-in replacements for a number of generally useful Flutter
framework widgets (all with the prefix `A`). Any widget can be made to support
state-based animation through components provided by Fleet (see
[`AnimatableStateMixin`][animatablestatemixin]). Issues or PRs for adding
support for more widgets are welcome!
[`AnimatableStatelessWidget`][AnimatableStatelessWidget]). Issues or PRs for
adding support for more widgets are welcome!

Note that we did not explicitly tell `setStateWithAnimation` what to animate.
This is because Fleet uses a **state-based** approach. All state changes caused
by executing the provided callback will be animated. Even the state changes
which are indirect, like the `color` parameter of `AColoredBox` going from
which are indirect, like the `color` parameter of `FleetColoredBox` going from
`Colors.grey` to `Colors.blue`. Fleet does this by tracking the state of
animatable parameters of animatable widgets from one build to the next.

Expand Down Expand Up @@ -170,10 +169,8 @@ The following provided widgets are specific to Fleet:
https://pub.dev/documentation/fleet/latest/fleet/withAnimationAsync.html
[setstatewithanimation]:
https://pub.dev/documentation/fleet/latest/fleet/AnimatingStateMixin/setStateWithAnimation.html
[animatablestatemixin]:
https://pub.dev/documentation/fleet/latest/fleet/AnimatableStateMixin-mixin.html
[AnimatableStatelessWidget]:
https://pub.dev/documentation/fleet/latest/fleet/AnimatableStatelessWidget-class.html
[animationspec]:
https://pub.dev/documentation/fleet/latest/fleet/AnimationSpec-class.html
[acoloredbox]:
https://pub.dev/documentation/fleet/latest/fleet/AColoredBox-class.html
[animated]: https://pub.dev/documentation/fleet/latest/fleet/Animated-class.html
2 changes: 1 addition & 1 deletion packages/fleet/example/lib/interactive_box_fleet.dart
@@ -1,5 +1,5 @@
import 'package:fleet/modifiers.dart';
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion packages/fleet/example/lib/interactive_box_flutter.dart
@@ -1,5 +1,5 @@
import 'package:fleet/modifiers.dart';
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';

void main() {
Expand Down
@@ -1,5 +1,5 @@
import 'package:fleet/modifiers.dart';
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';

void main() {
Expand Down
2 changes: 0 additions & 2 deletions packages/fleet/lib/fleet.dart
Expand Up @@ -4,8 +4,6 @@ export 'src/animation/animatable_render_object_widget.dart'
AnimatableSingleChildRenderObjectWidgetMixin;
export 'src/animation/animatable_stateless_widget.dart'
show AnimatableStatelessWidget;
export 'src/animation/animatable_widget_state.dart'
show AnimatableState, AnimatableStateMixin;
export 'src/animation/animate.dart'
show Animated, withAnimation, AnimatingStateMixin;
export 'src/animation/animation.dart'
Expand Down
103 changes: 0 additions & 103 deletions packages/fleet/lib/src/animation/animatable_widget_state.dart

This file was deleted.

5 changes: 2 additions & 3 deletions packages/fleet/lib/src/animation/animate.dart
Expand Up @@ -5,7 +5,6 @@ import '../widgets/basic_flutter_widgets.dart';
import '../widgets/uniform_padding.dart';
import 'animatable_render_object_widget.dart';
import 'animatable_stateless_widget.dart';
import 'animatable_widget_state.dart';
import 'animation.dart';
import 'transaction.dart';

Expand Down Expand Up @@ -143,8 +142,8 @@ mixin AnimatingStateMixin<T extends StatefulWidget> on State<T> {
/// {@template fleet.Animated.widgets}
///
/// Only widgets that support animating with Fleet will animate changes. To
/// implement support for this in your own widgets use [AnimatableStateMixin],
/// [AnimatableState], [AnimatableStatelessWidget] or
/// implement support for this in your own widgets use
/// [AnimatableStatelessWidget] or
/// [AnimatableSingleChildRenderObjectWidgetMixin].
///
/// The following provided widgets support animating with Fleet:
Expand Down
6 changes: 3 additions & 3 deletions packages/fleet/lib/src/animation/parameter.dart
Expand Up @@ -3,8 +3,8 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/widgets.dart' hide Animation;

import 'animatable_render_object_widget.dart';
import 'animatable_widget_state.dart';
import '../animation/animatable_render_object_widget.dart';
import '../animation/animatable_stateless_widget.dart';
import 'animation.dart';
import 'transaction.dart';

Expand Down Expand Up @@ -455,7 +455,7 @@ abstract class AnimatableParameterHost implements TickerProvider {
/// [AnimatableParameterHost].
///
/// Usually you don't need to use this mixin directly. Instead, use classes that
/// make use of it, such as [AnimatableState] and
/// make use of it, such as [AnimatableStatelessWidget] and
/// [AnimatableSingleChildRenderObjectWidgetMixin].
mixin AnimatableParameterHostMixin on Diagnosticable
implements AnimatableParameterHost {
Expand Down
Expand Up @@ -234,7 +234,7 @@ extension on WidgetTester {
}
}

class TestHost implements AnimatableStateMixin {
class TestHost implements AnimatableParameterHost {
TestHost(this.tester);

final WidgetTester tester;
Expand Down

0 comments on commit 6996c59

Please sign in to comment.