Skip to content
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
54 changes: 52 additions & 2 deletions example/lib/nstack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,55 @@
* `NStackFeatureHandlerWidget` with the `NStackVersionUpdateHandler` config,
* and you will get the version update data only once for an app life cycle.
*
* ⭐ Rate Reminder
*
* Rate reminders ask the user to rate the app on the platform-specific store once the amount of points from events reaches a certain threshold.
* Use `NStackFeatureHandlerWidget` with `NStackRateReminderHandler` config to integrate the rate reminder feature within your Flutter app.
* And use `postRateReminderEvent`API from `NStackRateReminders` to post points to the backend.
* This setup facilitates different strategies for handling the Rate Reminder
*
* - Default Adaptive Dialog:
* By default, `NStackRateReminderHandler.config()` with `void Function(NStackRateReminderAnswer)` callback is designed to automatically handle rate reminder.
* The callback will provide the user's answer.
* Example:
*
* ```dart
* NStackRateReminderHandler.config(
* onRateReminderAnswered: (rateReminderAnswer) {
*
* },
* )
* ```
*
* - Custom Handling:
* By passing a `void Function(NStackRateReminder)` callback to `NStackRateReminderHandler.config()`,
* you gain control over how the rate reminder alert is presented to the user. In this case, passing the
* `void Function(NStackRateReminderAnswer)` callback is unnecessary.
* Example:
*
* ```dart
* NStackRateReminderHandler.config(
* onRateReminder: (rateReminderInfo) {
*
* },
* )
* ```
*
* Or, if you don't want to use the `NStackFeatureHandlerWidget`,
* you can use the `getRateReminderInfo`, `postRateReminderEvent` and `postRateReminderAnswer` from `NStackRateReminders`.
* Example:
*
* ```dart
* WidgetsBinding.instance.addPostFrameCallback(
* (timeStamp) async {
* final rateReminderInfo =
* await context.nstack.rateReminders.getRateReminderInfo(
* defaultLocale: Localizations.localeOf(context),
* );
* },
* );
* ```
*
* 🛠️ IMPORTANT NOTES FOR SDK USERS
*
* The default environment for the NStack SDK is `prod`.
Expand All @@ -151,6 +200,7 @@ import 'package:nstack/src/sdk/localization/section_key_delegate.dart';
import 'package:nstack/src/sdk/widgets/nstack_base_widget.dart';

export 'package:nstack/src/models/app_open_platform.dart';
export 'package:nstack/src/models/nstack_rate_reminder_answer.dart';
export 'package:nstack/src/models/nstack_version_update_view_request.dart'
show NStackVersionUpdateViewAnswer, NStackVersionUpdateViewType;
export 'package:nstack/src/sdk/extensions/nstack_widget_extension.dart';
Expand Down Expand Up @@ -253,14 +303,14 @@ class NStackWidget extends NStackBaseWidget {
required Widget child,
AppOpenPlatform? platformOverride,
VoidCallback? onComplete,
bool? testMode,
bool testMode = false,
}) : super(
key: key,
child: child,
platformOverride: platformOverride,
onComplete: onComplete,
config: config,
testMode: testMode ?? false,
testMode: testMode,
localization: NStackLocalization(
config: config,
bundledLocalization: BundledLocalizationImpl.data(),
Expand Down
1 change: 1 addition & 0 deletions example/lib/routes/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class AppRouter extends $AppRouter {
AutoRoute(page: MessageExampleRoute.page),
AutoRoute(page: VersionUpdateExampleRoute.page),
AutoRoute(page: CombineExampleRoute.page),
AutoRoute(page: RateReminderExampleRoute.page),
];
}
65 changes: 43 additions & 22 deletions example/lib/routes/routes.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions example/lib/screens/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class MainScreen extends StatelessWidget {
'Combine Example',
),
),
MaterialButton(
onPressed: () => context.pushRoute(
const RateReminderExampleRoute(),
),
child: const Text(
'Rate Reminder Example',
),
),
],
),
),
Expand Down
54 changes: 54 additions & 0 deletions example/lib/screens/rate_reminder_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:auto_route/auto_route.dart';
import 'package:example/nstack.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

@RoutePage()
class RateReminderExampleScreen extends StatefulWidget {
const RateReminderExampleScreen({super.key});

@override
State<RateReminderExampleScreen> createState() =>
_RateReminderExampleScreenState();
}

class _RateReminderExampleScreenState extends State<RateReminderExampleScreen> {
@override
Widget build(BuildContext context) {
final localizationAsset = context.localizationAssest;

return NStackFeatureHandlerWidget(
features: [
NStackRateReminderHandler.config(
onRateReminderAnswered: (rateReminderAnswer) {
if (kDebugMode) {
print(rateReminderAnswer);
}
},
),
],
child: Scaffold(
appBar: AppBar(
title: Text(localizationAsset.test.testDollarSign),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Rate Reminder Example'),
MaterialButton(
onPressed: () async {
await context.nstack.rateReminders
.postRateReminderEvent(action: 'button-tapped');
},
child: const Text(
'Trigger Points',
),
),
],
),
),
),
);
}
}
6 changes: 0 additions & 6 deletions lib/src/models/app_open_data.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:nstack/src/models/localize_index.dart';
import 'package:nstack/src/models/nstack_message.dart';
import 'package:nstack/src/models/nstack_version_update.dart';
import 'package:nstack/src/models/rate_reminder.dart';
import 'package:nstack/src/models/terms.dart';
import 'package:nstack/src/other/extensions.dart';

Expand All @@ -13,7 +12,6 @@ class AppOpenData {
final DateTime? createdAt;
final DateTime? updatedAt;
final NStackMessage? message;
final RateReminder? rateReminder;
final List<Terms>? terms;

AppOpenData({
Expand All @@ -24,7 +22,6 @@ class AppOpenData {
required this.createdAt,
required this.updatedAt,
required this.message,
required this.rateReminder,
required this.terms,
});

Expand All @@ -48,9 +45,6 @@ class AppOpenData {
DateTime.parse,
),
message: (json['message'] as Map?)?.let(NStackMessage.fromJson),
rateReminder: json['rateReminder']?.let(
RateReminder.fromJson,
),
terms: json['terms']?.let((item) => item),
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/models/nstack_rate_reminder_answer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum NStackRateReminderAnswer {
positive,
negative,
skip,
}
Loading