Add Flutter client factory surface#1510
Conversation
Greptile SummaryThis PR adds a narrower
Confidence Score: 5/5Safe to merge — the factory surface is additive, the legacy setter path still works end-to-end, and the Realtime type guards address the previously flagged downcast issue. All changed code paths have been validated: factory methods build on the same No files require special attention. The only notes are stylistic improvements to the repeated casts in Important Files Changed
Reviews (2): Last reviewed commit: "Address Flutter client surface review co..." | Re-trigger Greptile |
|
Superseded by #1511, which now consolidates the Web, Flutter, and Apple isomorphic SDK changes. |
Summary
Adds the same client-side auth factory pattern to the generated Flutter SDK, scoped only to Flutter client output. The new factories provide a narrower public
ClientAuthsurface for factory-created clients while preserving the existingClient()constructor/setter style for compatibility.The recommended Flutter setup is now:
The old syntax is still supported:
Those legacy setter methods are now marked
@Deprecated. They remain available fromClient(), but factory-created clients are inferred asClientAuthand do not expose legacy setters.Auth Factories
All factories use named parameters. Common fields include
endPoint,projectId,endPointRealtime,locale, andselfSigned.Available Flutter client factories:
Client.fromBrowser(...)Client.fromSession(...)X-Appwrite-Session; useful when a session secret is explicitly available.Client.fromDevKey(...)Client.fromImpersonation(...)sessionand exactly one ofuserId,userEmail, oruserPhone.This PR intentionally does not add server-side factories such as API key, JWT, or cookie factories to Flutter. It only updates the client-side Flutter SDK surface.
Type Safety
Dart does not have the same conditional type machinery used by the Web SDK, so this PR uses nominal interfaces instead:
That means:
Client()keeps the full legacyClienttype and can still call setters.Client.fromBrowser(...)and the other factories returnClientAuth, so setters are not visible on inferred factory clients.ClientAuth, so both legacy and factory-created clients keep the same service construction syntax._client, so public.clientaccess is hidden.ClientAuth, so factory-created clients work withRealtime(client).Examples:
Implementation Details
templates/flutter/lib/src/client.dart.twigClientAuth, static client factories, deprecated legacy setters, and keepsClient()compatibility.templates/flutter/lib/src/client_base.dart.twigtemplates/flutter/lib/src/client_browser.dart.twigtemplates/flutter/lib/src/client_io.dart.twigtemplates/flutter/lib/src/service.dart.twigClientAuthand does not expose a publicclientfield.src/SDK/Language/Flutter.phptemplates/flutter/lib/services/service.dart.twig_clientandClientAuthconstructors while preservingService(client)syntax.templates/flutter/base/requests/*.twig_client.templates/flutter/lib/src/realtime*.twigClientAuth.templates/flutter/lib/package.dart.twigsrc/client.dartinto the library so service part files can referenceClientAuth.Compatibility Notes
Client().setEndpoint(...).setProject(...)still works.Client.fromBrowser(...),Client.fromSession(...),Client.fromDevKey(...), orClient.fromImpersonation(...)results.Account(client),TablesDB(client),Realtime(client), etc..clientproperty.Validation
Validation performed on this branch:
php example.php flutter clientcomposer lint-twigphp -l src/SDK/Language/Flutter.phpgit diff --checkflutter analyze --no-fatal-warnings --no-fatal-infosinexamples/flutterClient()and are reported as deprecatedRealtimeClient.fromBrowser(...).setProject(...)is rejectedAccount(Client.fromBrowser(...)).clientis rejectedFull
flutter testwas also run. It currently fails in two generated OAuth service fixture tests:Account.createOAuth2Session()expectsSessionbut mockedwebAuthreturnsnullAccount.createOAuth2Token()expectsTokenbut mockedwebAuthreturnsnullThose failures are unrelated to the client surface changes in this PR.