Skip to content

Commit

Permalink
Add fade in animation
Browse files Browse the repository at this point in the history
  • Loading branch information
sinasystem committed Jun 8, 2022
1 parent 2e852ab commit a96c2b4
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Preview | List screen | Detail Screen
│ | |──counter_button.dart
│ | |──empty_widget.dart
│ | |──furniture_list_view.dart
│ | |──fade_in_animation.dart
| | └──rating_bar.dart
└────📂controller
└──office_furniture_controller.dart
Expand All @@ -60,6 +61,7 @@ Package Name |
|[smooth_page_indicator](https://pub.dev/packages/smooth_page_indicator)
|[flutter_rating_bar](https://pub.dev/packages/flutter_rating_bar)
|[font_awesome_flutter](https://pub.dev/packages/font_awesome_flutter)
|[simple_animations](https://pub.dev/packages/simple_animations)


## Created & Maintained By
Expand Down
25 changes: 19 additions & 6 deletions lib/core/app_extension.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import 'package:flutter/material.dart';

import '../src/view/widget/fade_in_animation.dart';

extension StringExtension on String {
String get addOverFlow {
if (length < 15) {
Expand All @@ -6,21 +10,30 @@ extension StringExtension on String {
return "${substring(0, 15)}...";
}
}
double get dropSign{

double get dropSign {
return double.parse(replaceAll("\$", ""));
}
}

extension IterableExtension<T> on Iterable<T> {
Iterable<T> distinctBy(Object Function(T e) getCompareValue) {
var result = <T>[];
forEach((element) {
if (!result.any((x) => getCompareValue(x) == getCompareValue(element))) {
result.add(element);
}
});
forEach(
(element) {
if (!result
.any((x) => getCompareValue(x) == getCompareValue(element))) {
result.add(element);
}
},
);
return result;
}
}

extension WidgetExtension on Widget{
Widget fadeAnimation(double delay){
return FadeInAnimation(delay: delay, child: this);
}
}

17 changes: 9 additions & 8 deletions lib/src/view/screen/office_furniture_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:office_furniture_store/core/app_color.dart';
import 'package:office_furniture_store/core/app_extension.dart';
import 'package:office_furniture_store/core/app_style.dart';
import 'package:office_furniture_store/src/controller/office_furniture_controller.dart';
import 'package:office_furniture_store/src/view/widget/counter_button.dart';
Expand Down Expand Up @@ -80,7 +81,7 @@ class OfficeFurnitureDetailScreen extends StatelessWidget {
)
],
),
);
).fadeAnimation(1.3);
}

Widget furnitureImageSlider(double height) {
Expand Down Expand Up @@ -122,7 +123,7 @@ class OfficeFurnitureDetailScreen extends StatelessWidget {
),
),
],
),
).fadeAnimation(0.2),
);
}

Expand All @@ -143,17 +144,17 @@ class OfficeFurnitureDetailScreen extends StatelessWidget {
child: StarRatingBar(
score: furniture.score,
itemSize: 25,
),
).fadeAnimation(0.4),
),
const Padding(
padding: EdgeInsets.only(top: 20, bottom: 10),
Padding(
padding: const EdgeInsets.only(top: 20, bottom: 10),
child:
Text("Synopsis", style: h2Style, textAlign: TextAlign.end),
const Text("Synopsis", style: h2Style, textAlign: TextAlign.end).fadeAnimation(0.6),
),
Text(furniture.description,
maxLines: 5,
overflow: TextOverflow.ellipsis,
style: const TextStyle(color: Colors.black45)),
style: const TextStyle(color: Colors.black45)).fadeAnimation(0.8),
const SizedBox(height: 20),
Row(
children: [
Expand All @@ -170,7 +171,7 @@ class OfficeFurnitureDetailScreen extends StatelessWidget {
},
))
],
)
).fadeAnimation(1.0)
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/widget/cart_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CartListView extends StatelessWidget {
),
)
],
),
).fadeAnimation(0.4*index),
);
},
separatorBuilder: (BuildContext context, int index) {
Expand Down
33 changes: 33 additions & 0 deletions lib/src/view/widget/fade_in_animation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:simple_animations/simple_animations.dart';

enum AniProps { opacity, translateY }

class FadeInAnimation extends StatelessWidget {
final double delay;
final Widget child;

const FadeInAnimation({Key? key ,required this.delay, required this.child}):super(key: key);


@override
Widget build(BuildContext context) {
final tween = MultiTween<AniProps>()
..add(AniProps.opacity, Tween<double>(begin: 0.0, end: 1.0), const Duration(milliseconds: 500))
..add(AniProps.translateY, Tween<double>(begin: -30.0, end: 0.0), const Duration(milliseconds: 500),
Curves.easeOut);


return PlayAnimation<MultiTweenValues<AniProps>>(
delay: Duration(milliseconds: (500 * delay).round()),
duration: tween.duration,
tween: tween,
child: child,
builder: (context, child, value) => Opacity(
opacity: value.get(AniProps.opacity),
child: Transform.translate(
offset: Offset(0, value.get(AniProps.translateY),), child: child),
),
);
}
}
10 changes: 5 additions & 5 deletions lib/src/view/widget/furniture_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FurnitureListView extends StatelessWidget {
const SizedBox(width: 10),
Text(furniture.score.toString(), style: h4Style),
],
);
).fadeAnimation(1.0);
}

Widget _furnitureImage(String image) {
Expand All @@ -34,7 +34,7 @@ class FurnitureListView extends StatelessWidget {
width: 150,
height: 150,
),
);
).fadeAnimation(0.4);
}

Widget _listViewItem(Furniture furniture) {
Expand All @@ -44,7 +44,7 @@ class FurnitureListView extends StatelessWidget {
children: [
_furnitureImage(furniture.images[0]),
const SizedBox(height: 10),
Text(furniture.title.addOverFlow, style: h4Style),
Text(furniture.title.addOverFlow, style: h4Style).fadeAnimation(0.8),
_furnitureScore(furniture),
],
)
Expand All @@ -58,7 +58,7 @@ class FurnitureListView extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(furniture.title, style: h4Style),
Text(furniture.title, style: h4Style).fadeAnimation(0.8),
const SizedBox(height: 5),
_furnitureScore(furniture),
const SizedBox(height: 5),
Expand All @@ -67,7 +67,7 @@ class FurnitureListView extends StatelessWidget {
style: h5Style.copyWith(fontSize: 12),
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
).fadeAnimation(1.4)
],
),
),
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
simple_animations:
dependency: "direct main"
description:
name: simple_animations
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies:
smooth_page_indicator: ^1.0.0+2
flutter_rating_bar: ^4.0.0
font_awesome_flutter: ^10.1.0

simple_animations: ^4.0.1


dev_dependencies:
Expand Down

0 comments on commit a96c2b4

Please sign in to comment.