Skip to content

Commit

Permalink
Apply Dachary feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed Jan 28, 2024
1 parent b5811b0 commit 8991808
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
23 changes: 17 additions & 6 deletions examples/dart/test/app_services_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import "dart:isolate";

void main() {
const APP_ID = "example-testers-kvjdy";

group('App Services client - ', () {
test('Access App client', () {
// :snippet-start: access-app-client
final appConfig = AppConfiguration(APP_ID);
final app = App(appConfig);
//:snippet-end:
expect(app.currentUser, null);
expect(app, isNotNull);
expect(app.id, APP_ID);
});
test('App client advanced configuration', () {
// :snippet-start: app-client-advanced-configuration
Expand All @@ -23,7 +25,8 @@ void main() {
);
//:snippet-end:
final app = App(appConfig);
expect(app.currentUser, null);
expect(app, isNotNull);
expect(app.id, APP_ID);
expect(appConfig.defaultRequestTimeout, Duration(seconds: 120));
});

Expand All @@ -34,22 +37,27 @@ void main() {
final appConfig = AppConfiguration(APP_ID);
final app = App(appConfig);
final appId = app.id;
final receivePort = ReceivePort();
// :remove-start:
expect(app, isNotNull);
final receivePort = ReceivePort();
final anonUser =
await app.logIn(Credentials.anonymous(reuseCredentials: false));
expect(anonUser.id, app.currentUser?.id);
// :remove-end:

// Later, access the App instance on background isolate
await Isolate.spawn((List<Object> args) async {
final sendPort = args[0] as SendPort;
final appId = args[1] as String;

try {
final app = App.getById(appId); // :emphasize:
final backgroundApp = App.getById(appId); // :emphasize:

// ... Access App users
final user = app?.currentUser!;
final user = backgroundApp?.currentUser!;
expect(user, isNotNull); // :remove:

// ... Open and use the synced database as usual
// Use the App and user as needed.

sendPort.send('Background task completed');
} catch (e) {
Expand All @@ -62,6 +70,9 @@ void main() {
expect(message, equals('Background task completed'));
receivePort.close();
});
if (app.currentUser != null) {
app.deleteUser(anonUser);
}
});

test("Custom SSL Certificate", () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
final appConfig = AppConfiguration(APP_ID);
final app = App(appConfig);
final appId = app.id;
final receivePort = ReceivePort();

// Later, access the App instance on background isolate
await Isolate.spawn((List<Object> args) async {
final sendPort = args[0] as SendPort;
final appId = args[1] as String;

try {
final app = App.getById(appId);
final backgroundApp = App.getById(appId);

// ... Access App users
final user = app?.currentUser!;
final user = backgroundApp?.currentUser!;

// ... Open and use the synced database as usual
// Use the App and user as needed.

sendPort.send('Background task completed');
} catch (e) {
Expand Down
9 changes: 4 additions & 5 deletions source/sdk/flutter/app-services/connect-to-app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ once on the main isolate, ideally as soon as the app starts.
with the ``AppConfiguration`` you just created. In Flutter v1.7.0 and later,
this must be done on the main isolate, otherwise the SDK throws an error.

After you create the ``App``, you can access the constructed ``App``'s instance
After you create the ``App``, you can access the constructed ``App`` instance
on a background isolate using ``App.getById``. Refer to the
:ref:`Get App by ID <flutter-get-app-by-id>` section on this page for more
information.
Expand All @@ -63,8 +63,8 @@ information.
Advanced Configuration
----------------------

.. versionchanged:: 1.6.0
Deprecated ``App.localAppName`` and ``App.localAppVersion``.
.. deprecated:: 1.6.0
``App.localAppName`` and ``App.localAppVersion`` are no longer used.

You can add optional arguments to the ``AppConfiguration`` for more granular control
of your ``App`` client. You may want to add things like custom timeouts
Expand Down Expand Up @@ -97,5 +97,4 @@ the constructed instance on a background isolate by passing the App ID to the
:language: dart
:emphasize-lines: 12

Once you have the ``App`` instance, you can use it to work with users and synced
databases.
Once you have the ``App`` instance, you can use it to work with the App and users as needed.

0 comments on commit 8991808

Please sign in to comment.