Skip to content

Commit

Permalink
Support widget animations (#14)
Browse files Browse the repository at this point in the history
* Setup

* Refactor

* Refactor

* refactor

* Refactor, improve generics

* bump version

---------

Co-authored-by: souvikdas <[email protected]>
  • Loading branch information
deepakg202 and svk014 authored Jan 8, 2024
1 parent 70214b4 commit 521a26f
Show file tree
Hide file tree
Showing 19 changed files with 460 additions and 366 deletions.
129 changes: 2 additions & 127 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:blend_animation_kit/blend_animation_kit.dart';
import 'package:example/text_demo.dart';
import 'package:flutter/material.dart';

void main() {
Expand All @@ -16,132 +16,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData.dark(
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
List<Widget> get widgets => [
variant2(customText ?? "Great Thinkers", const TextStyle(fontSize: 40)),
variant3(
customText ?? "Coffee mornings", const TextStyle(fontSize: 30)),
variant4(
customText ?? "Beautiful Questions", const TextStyle(fontSize: 30)),
variant5(customText ?? "Animation 6", const TextStyle(fontSize: 40)),
variant6(customText ?? "Animation 7", const TextStyle(fontSize: 40)),
];

String? customText;
final textFieldController = TextEditingController();

@override
void dispose() {
textFieldController.dispose();
super.dispose();
}

double sliderVal = 1;
bool sliderActive = false;

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
children: [
TextField(
controller: textFieldController,
decoration: InputDecoration(
hintText: "Enter any text",
suffixIcon: TextButton.icon(
onPressed: () {
if (!mounted) return;
setState(() {
customText = null;
});
textFieldController.clear();
FocusManager.instance.primaryFocus?.unfocus();
},
icon: const Icon(Icons.cancel),
label: const Text("Cancel"),
),
),
onChanged: (val) {
if (!mounted) return;
setState(() {
customText = val;
});
},
),
Expanded(
child: Scrollbar(
child: ListView.separated(
key: ValueKey(customText),
padding: const EdgeInsets.all(10),
separatorBuilder: (context, index) => const SizedBox(
height: 10,
),
itemCount: widgets.length,
itemBuilder: (context, index) {
return Center(
child: LayoutBuilder(builder: (context, constraints) {
return Container(
width: sliderActive
? constraints.maxWidth * sliderVal
: null,
decoration: BoxDecoration(
border: Border.all(color: Colors.red)),
child: widgets[index],
);
}),
);
},
),
),
),
Slider(
min: 0,
max: 1,
value: sliderVal,
onChanged: sliderActive
? (val) {
setState(() {
sliderVal = val;
});
}
: null,
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Change Width"),
Checkbox(
value: sliderActive,
onChanged: (val) {
setState(() {
sliderActive = val ?? false;
sliderVal = 1.0;
});
}),
],
),
)
],
),
),
),
home: const TextDemo(title: 'Flutter Demo Home Page'),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'dart:math';

import 'package:blend_animation_kit/src/animation_input.dart';
import 'package:blend_animation_kit/src/pipeline/opacity.dart';
import 'package:blend_animation_kit/src/pipeline/pipeline_helpers.dart';
import 'package:blend_animation_kit/src/pipeline/pipeline_step.dart';
import 'package:blend_animation_kit/src/text_animation_widget.dart';
import 'package:blend_animation_kit/blend_animation_kit.dart';
import 'package:flutter/material.dart';

final PipelineStep variant2Pipeline = const OpacityStep(
Expand All @@ -16,12 +12,10 @@ final PipelineStep variant2Pipeline = const OpacityStep(
) +
PipelineHelpers.waitAndFadeOutAll();

Widget variant2(String text, TextStyle? textStyle) =>
TextAnimationWidget.fromInput(
animationInput: CharacterAnimationInput(text: text),
textStyle: textStyle,
pipelineStep: variant2Pipeline,
);
Widget variant2(String text, TextStyle? textStyle) => BlendAnimationWidget(
builder: BlendAnimationBuilder(CharacterAnimationInput(
text: text, textStyle: textStyle, textAlign: TextAlign.end))
.add(variant2Pipeline));

final PipelineStep variant3Pipeline = PipelineHelpers.opacityAndTransform(
initialOpacity: 1.0,
Expand All @@ -35,12 +29,10 @@ final PipelineStep variant3Pipeline = PipelineHelpers.opacityAndTransform(
) +
PipelineHelpers.waitAndFadeOutAll();

Widget variant3(String text, TextStyle? textStyle) =>
TextAnimationWidget.fromInput(
animationInput: CharacterAnimationInput(text: text),
textStyle: textStyle,
pipelineStep: variant3Pipeline,
);
Widget variant3(String text, TextStyle? textStyle) => BlendAnimationWidget(
builder: BlendAnimationBuilder(
CharacterAnimationInput(text: text, textStyle: textStyle))
.add(variant3Pipeline));

final PipelineStep variant4Pipeline = PipelineHelpers.opacityAndTransform(
initialOpacity: 0.0,
Expand All @@ -53,12 +45,10 @@ final PipelineStep variant4Pipeline = PipelineHelpers.opacityAndTransform(
) +
PipelineHelpers.waitAndFadeOutAll();

Widget variant4(String text, TextStyle? textStyle) =>
TextAnimationWidget.fromInput(
animationInput: CharacterAnimationInput(text: text),
textStyle: textStyle,
pipelineStep: variant4Pipeline,
);
Widget variant4(String text, TextStyle? textStyle) => BlendAnimationWidget(
builder: BlendAnimationBuilder(
CharacterAnimationInput(text: text, textStyle: textStyle))
.add(variant4Pipeline));

final PipelineStep variant5Pipeline = PipelineHelpers.opacityAndTransform(
initialOpacity: 0.0,
Expand All @@ -71,12 +61,10 @@ final PipelineStep variant5Pipeline = PipelineHelpers.opacityAndTransform(
) +
PipelineHelpers.waitAndFadeOutAll();

Widget variant5(String text, TextStyle? textStyle) =>
TextAnimationWidget.fromInput(
animationInput: CharacterAnimationInput(text: text),
textStyle: textStyle,
pipelineStep: variant5Pipeline,
);
Widget variant5(String text, TextStyle? textStyle) => BlendAnimationWidget(
builder: BlendAnimationBuilder(
CharacterAnimationInput(text: text, textStyle: textStyle))
.add(variant5Pipeline));

final PipelineStep variant6Pipeline = PipelineHelpers.opacityAndTransform(
initialOpacity: 0.0,
Expand All @@ -89,9 +77,7 @@ final PipelineStep variant6Pipeline = PipelineHelpers.opacityAndTransform(
) +
PipelineHelpers.waitAndFadeOutAll();

Widget variant6(String text, TextStyle? textStyle) =>
TextAnimationWidget.fromInput(
animationInput: CharacterAnimationInput(text: text),
textStyle: textStyle,
pipelineStep: variant6Pipeline,
);
Widget variant6(String text, TextStyle? textStyle) => BlendAnimationWidget(
builder: BlendAnimationBuilder(
CharacterAnimationInput(text: text, textStyle: textStyle))
.add(variant6Pipeline));
127 changes: 127 additions & 0 deletions example/lib/text_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import 'package:example/predefined_animations.dart';
import 'package:flutter/material.dart';

class TextDemo extends StatefulWidget {
const TextDemo({super.key, required this.title});

final String title;

@override
State<TextDemo> createState() => _TextDemoState();
}

class _TextDemoState extends State<TextDemo> {
List<Widget> get widgets => [
variant2(customText ?? "Great Thinkers", const TextStyle(fontSize: 40)),
variant3(
customText ?? "Coffee mornings", const TextStyle(fontSize: 30)),
variant4(
customText ?? "Beautiful Questions", const TextStyle(fontSize: 30)),
variant5(customText ?? "Animation 6", const TextStyle(fontSize: 40)),
variant6(customText ?? "Animation 7", const TextStyle(fontSize: 40)),
];

String? customText;
final textFieldController = TextEditingController();

@override
void dispose() {
textFieldController.dispose();
super.dispose();
}

double sliderVal = 1;
bool sliderActive = false;

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
children: [
TextField(
controller: textFieldController,
decoration: InputDecoration(
hintText: "Enter any text",
suffixIcon: TextButton.icon(
onPressed: () {
if (!mounted) return;
setState(() {
customText = null;
});
textFieldController.clear();
FocusManager.instance.primaryFocus?.unfocus();
},
icon: const Icon(Icons.cancel),
label: const Text("Cancel"),
),
),
onChanged: (val) {
if (!mounted) return;
setState(() {
customText = val;
});
},
),
Expanded(
child: Scrollbar(
child: ListView.separated(
key: ValueKey(customText),
padding: const EdgeInsets.all(10),
separatorBuilder: (context, index) => const SizedBox(
height: 10,
),
itemCount: widgets.length,
itemBuilder: (context, index) {
return Center(
child: LayoutBuilder(builder: (context, constraints) {
return Container(
width: sliderActive
? constraints.maxWidth * sliderVal
: null,
decoration: BoxDecoration(
border: Border.all(color: Colors.red)),
child: widgets[index],
);
}),
);
},
),
),
),
Slider(
min: 0,
max: 1,
value: sliderVal,
onChanged: sliderActive
? (val) {
setState(() {
sliderVal = val;
});
}
: null,
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Change Width"),
Checkbox(
value: sliderActive,
onChanged: (val) {
setState(() {
sliderActive = val ?? false;
sliderVal = 1.0;
});
}),
],
),
)
],
),
),
),
);
}
}
Loading

0 comments on commit 521a26f

Please sign in to comment.