FakeInAppMessaging class

An InAppMessaging whose campaigns are a list in memory, for widget tests of an app's screens and button callbacks, without Supabase.

It goes where app code takes an InAppMessaging. trigger shows the same campaign the real client would, with the same rules (the event, the end date, the frequency caps, messagesSuppressed, shouldShow, one message at a time), through the same showInAppMessage, and records the impression, click or dismissal in events instead of sending it:

messaging.trigger('purchase_done');
await tester.pumpAndSettle();
await tester.tap(find.text('Rate us'));
await tester.pumpAndSettle();
expect(messaging.events, [
  (campaignId: 'rate', kind: 'impression'),
  (campaignId: 'rate', kind: 'click'),
]);

Nothing fires by itself: call trigger('app_open') where the real client would, after the first fetch and when the app is shown again.

Implemented types

Constructors

FakeInAppMessaging({required GlobalKey<NavigatorState> navigatorKey, List<InAppMessage> messages = const [], ValueChanged<String>? onUrl, InAppMessageBuilder? builder, bool shouldShow(InAppMessage message)?})
Shows messages, highest priority first, on navigatorKey's navigator, as InAppMessaging.initialize does with what it fetched.

Properties

events → List<({String campaignId, String kind})>
What was recorded, oldest first: impression when a message is shown, then click when a url button closes it, or dismiss when anything else does. The real client sends these to iam_track for a signed-in user.
final
hashCode → int
The hash code for this object.
no setterinherited
messages ↔ List<InAppMessage>
The campaigns, as if fetched, highest priority first. Set it to pretend the server's campaigns changed.
getter/setter pair
messagesSuppressed ↔ bool
Whether messages are kept off screen, like Firebase's setMessagesSuppressed. Set it on screens that must not be interrupted, such as checkout or a video, and clear it when leaving them. A trigger while it is set is dropped, not delayed, and a message already on screen stays.
getter/setter pairoverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → void
Drops the campaigns, as InAppMessaging.dispose does. A message already on screen stays until it is closed.
override
fetch() → Future<void>
Does nothing: there is no server, and messages is what was fetched.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
trigger(String event) → void
Like InAppMessaging.trigger.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited