-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from Countly/present_calls
[Flutter] tweak present calls
- Loading branch information
Showing
8 changed files
with
261 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
typedef OnClosedCallback = void Function(); | ||
typedef OnFinishedCallback = void Function(String error); | ||
|
||
class FeedbackCallback { | ||
final OnClosedCallback onClosed; | ||
final OnFinishedCallback onFinished; | ||
|
||
FeedbackCallback({required this.onClosed, required this.onFinished}); | ||
} | ||
|
||
abstract class Feedback { | ||
Future<void> presentNPS([String? nameIDorTag, FeedbackCallback? feedbackCallback]); | ||
|
||
Future<void> presentRating([String? nameIDorTag, FeedbackCallback? feedbackCallback]); | ||
|
||
Future<void> presentSurvey([String? nameIDorTag, FeedbackCallback? feedbackCallback]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'dart:convert'; | ||
|
||
import 'countly_flutter.dart'; | ||
import 'countly_state.dart'; | ||
import 'feedback.dart'; | ||
|
||
class FeedbackInternal implements Feedback { | ||
FeedbackInternal(this._countlyState); | ||
final CountlyState _countlyState; | ||
FeedbackCallback? _feedbackCallback; | ||
FeedbackCallback? get feedbackCallback => _feedbackCallback; | ||
set feedbackCallback(FeedbackCallback? callback) { | ||
// Add any validation or custom logic here if needed | ||
_feedbackCallback = callback; | ||
} | ||
|
||
@override | ||
Future<void> presentNPS([String? nameIDorTag, FeedbackCallback? feedbackCallback]) async { | ||
if (!_countlyState.isInitialized) { | ||
Countly.log('presentNPS, "initWithConfig" must be called before "presentNPS"', logLevel: LogLevel.ERROR); | ||
feedbackCallback?.onFinished('init must be called before presentNPS'); | ||
return; | ||
} | ||
|
||
_feedbackCallback = feedbackCallback; | ||
Countly.log('Calling "presentNPS" with nameIDorTag: [$nameIDorTag]'); | ||
await invokeFeedbackMethod('presentNPS', nameIDorTag); | ||
} | ||
|
||
@override | ||
Future<void> presentRating([String? nameIDorTag, FeedbackCallback? feedbackCallback]) async { | ||
if (!_countlyState.isInitialized) { | ||
Countly.log('presentRating, "initWithConfig" must be called before "presentRating"', logLevel: LogLevel.ERROR); | ||
feedbackCallback?.onFinished('init must be called before presentRating'); | ||
return; | ||
} | ||
|
||
_feedbackCallback = feedbackCallback; | ||
Countly.log('Calling "presentRating" with nameIDorTag: [$nameIDorTag]'); | ||
await invokeFeedbackMethod('presentRating', nameIDorTag); | ||
} | ||
|
||
@override | ||
Future<void> presentSurvey([String? nameIDorTag, FeedbackCallback? feedbackCallback]) async { | ||
if (!_countlyState.isInitialized) { | ||
Countly.log('presentSurvey, "initWithConfig" must be called before "presentSurvey"', logLevel: LogLevel.ERROR); | ||
feedbackCallback?.onFinished('init must be called before presentSurvey'); | ||
return; | ||
} | ||
|
||
_feedbackCallback = feedbackCallback; | ||
Countly.log('Calling "presentSurvey" with nameIDorTag: [$nameIDorTag]'); | ||
await invokeFeedbackMethod('presentSurvey', nameIDorTag); | ||
} | ||
|
||
Future<void> invokeFeedbackMethod(String methodName, String? nameIDorTag){ | ||
final args = []; | ||
nameIDorTag ??= ''; | ||
args.add(nameIDorTag); | ||
|
||
return _countlyState.channel.invokeMethod(methodName, <String, dynamic>{'data': json.encode(args)}); | ||
} | ||
} |