coditation_animator 0.0.9
coditation_animator: ^0.0.9 copied to clipboard
Flutter package to ease building animations
example/lib/main.dart
import 'dart:math';
import 'package:coditation_animator/coditation_animator.dart';
import 'package:example/current_animator/current_animator_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(home: AnimatorPlayground());
}
}
class AnimatorPlayground extends StatelessWidget {
AnimatorPlayground({Key? key}) : super(key: key);
final GlobalKey<AnimatorWidgetState> rootAnimatorStateKey = GlobalKey();
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => CurrentAnimatorBloc(),
child: Scaffold(
appBar: AppBar(title: const Text("Animator Playground")),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BlocBuilder<CurrentAnimatorBloc, CurrentAnimatorState>(
builder: (context, state) {
return Text(
state.currentAnimatorConfig?.runtimeType.toString() ?? "",
);
},
),
const SizedBox(height: 200),
MultiAnimator(
animatorStateListener: (context, animatorState) {
debugPrint(
animatorState.currentAnimatorConfig?.runtimeType.toString(),
);
if (animatorState.currentAnimatorConfig == null) return;
BlocProvider.of<CurrentAnimatorBloc>(context).add(
SetCurrentAnimatorConfig(
animatorConfig: animatorState.currentAnimatorConfig!,
),
);
},
rootAnimatorWidgetStateKey: rootAnimatorStateKey,
animatorConfigs: [
AnimatorConfig.rotate(
curve: Curves.bounceIn,
angle: pi / 4,
animationDuration: const Duration(seconds: 2),
),
AnimatorConfig.flipY(curve: Curves.bounceIn),
AnimatorConfig.fadeOut(
curve: Curves.linear,
animationDuration: const Duration(seconds: 2),
),
AnimatorConfig.fadeIn(curve: Curves.fastOutSlowIn),
AnimatorConfig.flipX(
curve: Curves.bounceIn,
animationDuration: const Duration(seconds: 2),
),
AnimatorConfig.scaleIn(curve: Curves.bounceOut, scaleIn: 1),
AnimatorConfig.rotate(
curve: Curves.bounceIn,
animationDuration: const Duration(seconds: 2),
angle: -pi / 4,
),
AnimatorConfig.scaleOut(
curve: Curves.bounceInOut,
scaleOut: 1,
),
],
child: Container(
height: 50,
width: 100,
color: Colors.red,
),
),
const SizedBox(height: 100),
AnimatorActions(
handleForward: rootAnimatorStateKey.forward,
handleReverse: rootAnimatorStateKey.reverse,
handleRepeat: rootAnimatorStateKey.repeat,
)
],
),
),
),
);
}
}
class AnimatorActions extends StatelessWidget {
const AnimatorActions({
Key? key,
this.handleForward,
this.handleReverse,
this.handleRepeat,
}) : super(key: key);
final void Function()? handleForward;
final void Function()? handleReverse;
final void Function()? handleRepeat;
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton.extended(
heroTag: "Forward",
onPressed: handleForward,
tooltip: "Forward",
label: const Text("Forward"),
icon: const Icon(Icons.forward),
),
FloatingActionButton.extended(
heroTag: "Reverse",
onPressed: handleReverse,
tooltip: "Reverse",
label: const Text("Reverse"),
icon: const Icon(Icons.undo),
),
FloatingActionButton.extended(
heroTag: "Repeat",
onPressed: handleRepeat,
tooltip: "Repeat",
label: const Text("Repeat"),
icon: const Icon(Icons.repeat),
),
],
),
),
],
);
}
}