Hi All,
I am trying to add the credentials via ArcGISEnvironment.authenticationManager.arcGISCredentialStore.addForUri()
final credentialMap = {
"token": token,
"userId": username,
"expiration": expireTime.toIso8601String(),
};
final tokenCredential = ArcGISCredential.fromJson(credentialMap);
// Add credential to the store
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.addForUri(
credential: tokenCredential,
uri: Uri.parse(portalURL),
);
final portal = Portal.arcGISOnline(
connection: PortalConnection.authenticated,
);
await portal.load();
You don't need to use WebView to login. You can do that directly through the Flutter Maps SDK using TokenCredential with this approach:
final credential = await TokenCredential.create( uri: Uri.parse(portalURL), username: username, password: password, );
Add the credential to the credential store: This is where you were getting the null error. Use the TokenCredential directly:
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.addForUri( credential: credential, // Use the TokenCredential, not a JSON map uri: Uri.parse(portalURL), );
Create and load the authenticated portal:
final portal = Portal.arcGISOnline( connection: PortalConnection.authenticated, ); await portal.load();
Get the license info for offline functionality: This is what you need for offline Portal APIs:
final licenseInfo = await portal.fetchLicenseInfo(); print('License: ${licenseInfo.toJson()}');
// You'd get something like: {licenseString: LICENSE_KEY}
This should eliminate your null pointer exception and get you the offline licensing you're looking for.
Checkout this sample for a full example: https://github.com/Esri/arcgis-maps-sdk-flutter-samples/tree/main/lib/samples/authenticate_with_toke...
Let me know if you have any questions!