Skip to content

Commit

Permalink
Added support for flutter_rating_bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Mar 18, 2021
1 parent f643bab commit 06b752a
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 151 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.0
* Added support for `flutter_rating_bar`.

## 1.0.0+2
* Fixed some problems with the Dart analyzer.

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ rateMyApp.init().then((_) {
return true; // Return false if you want to cancel the click event.
},
ignoreNativeDialog: Platform.isAndroid, // Set to false if you want to show the Apple's native app rating dialog on iOS or Google's native app rating dialog (depends on the current Platform).
dialogStyle: DialogStyle(), // Custom dialog styles.
dialogStyle: const DialogStyle(), // Custom dialog styles.
onDismissed: () => rateMyApp.callEvent(RateMyAppEventType.laterButtonPressed), // Called when the user dismissed the dialog (either by taping outside or by pressing the "back" button).
// contentBuilder: (context, defaultContent) => content, // This one allows you to change the default dialog content.
// actionsBuilder: (context) => [], // This one allows you to use your own buttons.
);
// Or if you prefer to show a star rating bar :
// Or if you prefer to show a star rating bar (powered by `flutter_rating_bar`) :
rateMyApp.showStarRateDialog(
context,
Expand All @@ -129,12 +129,12 @@ rateMyApp.init().then((_) {
];
},
ignoreNativeDialog: Platform.isAndroid, // Set to false if you want to show the Apple's native app rating dialog on iOS or Google's native app rating dialog (depends on the current Platform).
dialogStyle: DialogStyle( // Custom dialog styles.
dialogStyle: const DialogStyle( // Custom dialog styles.
titleAlign: TextAlign.center,
messageAlign: TextAlign.center,
messagePadding: EdgeInsets.only(bottom: 20),
),
starRatingOptions: StarRatingOptions(), // Custom star bar rating options.
starRatingOptions: const StarRatingOptions(), // Custom star bar rating options.
onDismissed: () => rateMyApp.callEvent(RateMyAppEventType.laterButtonPressed), // Called when the user dismissed the dialog (either by taping outside or by pressing the "back" button).
);
}
Expand All @@ -160,7 +160,7 @@ RateMyApp rateMyApp = RateMyApp(
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
WidgetsBinding.instance?.addPostFrameCallback((_) async {
await rateMyApp.init();
if (mounted && rateMyApp.shouldOpenDialog) {
rateMyApp.showRateDialog(context);
Expand Down Expand Up @@ -266,4 +266,5 @@ You have a lot of options to contribute to this project ! You can :
This library depends on some other libraries :

* [shared_preferences](https://pub.dev/packages/shared_preferences)
* [smooth_star_rating](https://pub.dev/packages/smooth_star_rating)
* [flutter_rating_bar](https://pub.dev/packages/flutter_rating_bar)
* [pedantic](https://pub.dev/packages/pedantic)
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'fr.skyost.rate_my_app'
version '0.7.1'
version '1.1.0'

buildscript {
ext.kotlin_version = '1.3.50'
Expand All @@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "fr.skyost.rate_my_app"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
9 changes: 8 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_rating_bar:
dependency: transitive
description:
name: flutter_rating_bar
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -169,7 +176,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0+2"
version: "1.1.0"
shared_preferences:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion ios/rate_my_app.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'rate_my_app'
s.version = '1.0.0'
s.version = '1.1.0'
s.summary = 'Allows to kindly ask users to rate your app if custom conditions are met (eg. install time, number of launches, etc...).'
s.description = <<-DESC
Allows to kindly ask users to rate your app if custom conditions are met (eg. install time, number of launches, etc...).
Expand Down
84 changes: 65 additions & 19 deletions lib/src/dialogs.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.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';

/// A simple dialog button click listener.
Expand Down Expand Up @@ -154,7 +154,7 @@ class RateMyAppStarDialog extends StatefulWidget {
});

@override
State<StatefulWidget> createState() => RateMyAppStarDialogState();
State<StatefulWidget> createState() => _RateMyAppStarDialogState();

/// Used when there is no onRatingChanged callback.
List<Widget> _defaultOnRatingChanged(BuildContext context, double? rating) =>
Expand All @@ -175,14 +175,14 @@ class RateMyAppStarDialog extends StatefulWidget {
}

/// The Rate my app star dialog state.
class RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
class _RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
/// The current rating.
double? _currentRating;
late double currentRating;

@override
void initState() {
super.initState();
_currentRating = widget.starRatingOptions.initialRating;
currentRating = widget.starRatingOptions.initialRating;
}

@override
Expand All @@ -199,19 +199,7 @@ class RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
textAlign: widget.dialogStyle.messageAlign,
),
),
SmoothStarRating(
onRatingChanged: (rating) {
setState(() => _currentRating = rating);
},
color: widget.starRatingOptions.starsFillColor,
borderColor: widget.starRatingOptions.starsBorderColor,
spacing: widget.starRatingOptions.starsSpacing,
size: widget.starRatingOptions.starsSize,
allowHalfRating: widget.starRatingOptions.allowHalfRating,
halfFilledIconData: widget.starRatingOptions.halfFilledIconData,
filledIconData: widget.starRatingOptions.filledIconData,
rating: _currentRating == null ? 0.0 : _currentRating!.toDouble(),
),
createRatingBar(),
],
),
);
Expand All @@ -229,9 +217,67 @@ class RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
contentPadding: widget.dialogStyle.contentPadding,
shape: widget.dialogStyle.dialogShape,
actions: (widget.actionsBuilder ?? widget._defaultOnRatingChanged)(
context, _currentRating),
context, currentRating),
);
}

/// Creates the rating bar.
RatingBar createRatingBar() {
if (widget.starRatingOptions.itemBuilder == null) {
return RatingBar(
onRatingUpdate: (rating) {
setState(() => currentRating = rating);
},
ratingWidget: widget.starRatingOptions.ratingWidget ??
createDefaultRatingWidget(),
initialRating: widget.starRatingOptions.initialRating,
minRating: widget.starRatingOptions.minRating,
allowHalfRating: widget.starRatingOptions.allowHalfRating,
itemPadding: widget.starRatingOptions.itemPadding,
itemSize: widget.starRatingOptions.itemSize,
itemCount: widget.starRatingOptions.itemCount,
glow: widget.starRatingOptions.glow,
glowRadius: widget.starRatingOptions.glowRadius,
tapOnlyMode: widget.starRatingOptions.tapOnlyMode,
wrapAlignment: widget.starRatingOptions.wrapAlignment,
);
}
return RatingBar.builder(
onRatingUpdate: (rating) {
setState(() => currentRating = rating);
},
itemBuilder: widget.starRatingOptions.itemBuilder!,
initialRating: widget.starRatingOptions.initialRating,
minRating: widget.starRatingOptions.minRating,
allowHalfRating: widget.starRatingOptions.allowHalfRating,
itemPadding: widget.starRatingOptions.itemPadding,
itemSize: widget.starRatingOptions.itemSize,
itemCount: widget.starRatingOptions.itemCount,
glow: widget.starRatingOptions.glow,
glowRadius: widget.starRatingOptions.glowRadius,
tapOnlyMode: widget.starRatingOptions.tapOnlyMode,
wrapAlignment: widget.starRatingOptions.wrapAlignment,
);
}

/// Creates the default rating widget.
RatingWidget createDefaultRatingWidget() => RatingWidget(
full: Icon(
Icons.star,
color: Colors.orangeAccent,
size: widget.starRatingOptions.itemSize,
),
half: Icon(
Icons.star_half,
color: Colors.orangeAccent,
size: widget.starRatingOptions.itemSize,
),
empty: Icon(
Icons.star_border,
color: Colors.orangeAccent,
size: widget.starRatingOptions.itemSize,
),
);
}

/// A Rate my app dialog button with a text, a validator and a callback.
Expand Down
90 changes: 0 additions & 90 deletions lib/src/smooth_star_rating.dart

This file was deleted.

Loading

0 comments on commit 06b752a

Please sign in to comment.