Skip to content

Commit

Permalink
Removed the non-null safe dependency smoothratingbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Mar 5, 2021
1 parent c520650 commit a42cf2d
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 24 deletions.
13 changes: 3 additions & 10 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "1.0.0+2"
shared_preferences:
dependency: transitive
description:
Expand Down Expand Up @@ -217,13 +217,6 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
smooth_star_rating:
dependency: transitive
description:
name: smooth_star_rating
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -295,5 +288,5 @@ packages:
source: hosted
version: "0.2.0"
sdks:
dart: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=2.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
4 changes: 2 additions & 2 deletions lib/src/dialogs.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:rate_my_app/rate_my_app.dart';
import 'package:rate_my_app/src/core.dart';
import 'package:rate_my_app/src/smooth_star_rating.dart';
import 'package:rate_my_app/src/style.dart';
import 'package:smooth_star_rating/smooth_star_rating.dart';

/// A simple dialog button click listener.
typedef RateMyAppDialogButtonClickListener = bool Function(
Expand Down Expand Up @@ -200,7 +200,7 @@ class RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
),
),
SmoothStarRating(
onRated: (rating) {
onRatingChanged: (rating) {
setState(() => _currentRating = rating);
},
color: widget.starRatingOptions.starsFillColor,
Expand Down
90 changes: 90 additions & 0 deletions lib/src/smooth_star_rating.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Credits : https://github.com/thangmam/smoothratingbar.

import 'package:flutter/material.dart';

typedef RatingChangeCallback = void Function(double rating);

class SmoothStarRating extends StatelessWidget {
final int starCount;
final double rating;
final RatingChangeCallback? onRatingChanged;
final Color? color;
final Color? borderColor;
final double size;
final bool allowHalfRating;
final IconData? filledIconData;
final IconData? halfFilledIconData;
final IconData? defaultIconData; //this is needed only when having fullRatedIconData && halfRatedIconData
final double spacing;

const SmoothStarRating({
this.starCount = 5,
this.spacing = 0.0,
this.rating = 0.0,
this.defaultIconData,
this.onRatingChanged,
this.color,
this.borderColor,
this.size = 25,
this.filledIconData,
this.halfFilledIconData,
this.allowHalfRating = true,
});

Widget buildStar(BuildContext context, int index) {
Icon icon;
if (index >= rating) {
icon = Icon(
defaultIconData ?? Icons.star_border,
color: borderColor ?? Theme.of(context).primaryColor,
size: size,
);
} else if (index > rating - (allowHalfRating ? 0.5 : 1.0) && index < rating) {
icon = Icon(
halfFilledIconData ?? Icons.star_half,
color: color ?? Theme.of(context).primaryColor,
size: size,
);
} else {
icon = Icon(
filledIconData ?? Icons.star,
color: color ?? Theme.of(context).primaryColor,
size: size,
);
}

return GestureDetector(
onTap: () {
if (onRatingChanged != null) {
onRatingChanged!(index + 1.0);
}
},
onHorizontalDragUpdate: (dragDetails) {
RenderBox box = context.findRenderObject() as RenderBox;
Offset position = box.globalToLocal(dragDetails.globalPosition);
double i = position.dx / size;
double newRating = allowHalfRating ? i : i.round().toDouble();
if (newRating > starCount) {
newRating = starCount.toDouble();
}
if (newRating < 0) {
newRating = 0.0;
}
if (onRatingChanged != null) {
onRatingChanged!(newRating);
}
},
child: icon,
);
}

@override
Widget build(BuildContext context) => Material(
color: Colors.transparent,
child: Wrap(
alignment: WrapAlignment.start,
spacing: spacing,
children: List.generate(starCount, (index) => buildStar(context, index)),
),
);
}
11 changes: 2 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
smooth_star_rating:
dependency: "direct main"
description:
name: smooth_star_rating
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -192,5 +185,5 @@ packages:
source: hosted
version: "0.2.0"
sdks:
dart: ">=2.12.0-259.9.beta <3.0.0"
flutter: ">=2.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
name: rate_my_app
description: Allows to kindly ask users to rate your app if custom conditions are met (eg. install time, number of launches, etc...).
version: 1.0.0 # Remember to also change the version in "ios/rate_my_app.podspec" and "android/build.gradle".
version: 1.0.0+2 # Remember to also change the version in "ios/rate_my_app.podspec" and "android/build.gradle".
homepage: https://github.com/Skyost/RateMyApp

environment:
sdk: '>=2.12.0 <3.0.0'
flutter: ">=2.0.0"
flutter: ">=1.12.0"

dependencies:
shared_preferences: ^2.0.3
smooth_star_rating: ^1.1.1
pedantic: ^1.11.0
flutter:
sdk: flutter
Expand Down

0 comments on commit a42cf2d

Please sign in to comment.