Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter that allows to add image to the Rate us pop up #144

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ rateMyApp.init().then((_) {
rateMyApp.showRateDialog(
context,
title: 'Rate this app', // The dialog title.
imagePath: 'assets/include_in_app/images/rate_us_image.png',
message: 'If you like this app, please take a little bit of your time to review it !\nIt really helps us and it shouldn\'t take you more than one minute.', // The dialog message.
rateButton: 'RATE', // The dialog "rate" button text.
noButton: 'NO THANKS', // The dialog "no" button text.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class RateMyApp {
Future<void> showRateDialog(
BuildContext context, {
String? title,
String? imagePath,
String? message,
DialogContentBuilder? contentBuilder,
DialogActionsBuilder? actionsBuilder,
Expand All @@ -136,6 +137,7 @@ class RateMyApp {
RateMyAppDialog rateMyAppDialog = RateMyAppDialog(
this,
title: title ?? 'Rate this app',
image: imagePath,
message: message ?? 'If you like this app, please take a little bit of your time to review it !\nIt really helps us and it shouldn\'t take you more than one minute.',
contentBuilder: contentBuilder ?? ((context, defaultContent) => defaultContent),
actionsBuilder: actionsBuilder,
Expand Down Expand Up @@ -177,6 +179,7 @@ class RateMyApp {
Future<void> showStarRateDialog(
BuildContext context, {
String? title,
String? imagePath,
String? message,
DialogContentBuilder? contentBuilder,
StarDialogActionsBuilder? actionsBuilder,
Expand All @@ -201,6 +204,7 @@ class RateMyApp {
RateMyAppStarDialog starRateDialog = RateMyAppStarDialog(
this,
title: title ?? 'Rate this app',
image: imagePath,
message: message ?? 'You like this app ? Then take a little bit of your time to leave a rating :',
contentBuilder: contentBuilder ?? ((context, defaultContent) => defaultContent),
actionsBuilder: actionsBuilder,
Expand Down
42 changes: 40 additions & 2 deletions lib/src/dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class RateMyAppDialog extends StatelessWidget {
/// The dialog's title.
final String title;

/// Image parameter
final String? image;

/// The dialog's message.
final String message;

Expand Down Expand Up @@ -54,6 +57,7 @@ class RateMyAppDialog extends StatelessWidget {
this.rateMyApp, {
Key? key,
required this.title,
this.image,
required this.message,
required this.contentBuilder,
this.actionsBuilder,
Expand All @@ -77,6 +81,21 @@ class RateMyAppDialog extends StatelessWidget {
),
);

// Add the image to the content if it's provided
List<Widget> dialogContent = [];
if (image != null) {
dialogContent.add(
Column(
children: [
Image.asset(
image!,
),
],
),
);
}
dialogContent.add(content);

return AlertDialog(
title: Padding(
padding: dialogStyle.titlePadding,
Expand All @@ -86,7 +105,7 @@ class RateMyAppDialog extends StatelessWidget {
textAlign: dialogStyle.titleAlign,
),
),
content: contentBuilder(context, content),
content: contentBuilder(context, Column(mainAxisSize: MainAxisSize.min, children: dialogContent)),
contentPadding: dialogStyle.contentPadding,
shape: dialogStyle.dialogShape,
actions: (actionsBuilder ?? _defaultActionsBuilder)(context),
Expand Down Expand Up @@ -120,6 +139,9 @@ class RateMyAppStarDialog extends StatefulWidget {
/// The dialog's title.
final String title;

/// Image parameter
final String? image;

/// The dialog's message.
final String message;

Expand All @@ -140,6 +162,7 @@ class RateMyAppStarDialog extends StatefulWidget {
this.rateMyApp, {
Key? key,
required this.title,
this.image,
required this.message,
required this.contentBuilder,
this.actionsBuilder,
Expand Down Expand Up @@ -197,6 +220,21 @@ class _RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
),
);

// Add the image to the content if it's provided
List<Widget> dialogContent = [];
if (widget.image != null) {
dialogContent.add(
Column(
children: [
Image.asset(
widget.image!,
),
],
),
);
}
dialogContent.add(content);

return AlertDialog(
title: Padding(
padding: widget.dialogStyle.titlePadding,
Expand All @@ -206,7 +244,7 @@ class _RateMyAppStarDialogState extends State<RateMyAppStarDialog> {
textAlign: widget.dialogStyle.titleAlign,
),
),
content: widget.contentBuilder(context, content),
content: widget.contentBuilder(context, Column(mainAxisSize: MainAxisSize.min, children: dialogContent)),
contentPadding: widget.dialogStyle.contentPadding,
shape: widget.dialogStyle.dialogShape,
actions: (widget.actionsBuilder ?? widget._defaultOnRatingChanged)(context, currentRating),
Expand Down