ElevatedButton(
onPressed: () async {
const baseUrl = '${AppwriteConstants.endPoint}/account/sessions/oauth2/apple';
final queryParams = {'project': AppwriteConstants.projectId, 'scope': 'email name'};
final fullUrl = Uri.parse(baseUrl).replace(queryParameters: queryParams);
try {
final responseUrl = await FlutterWebAuth2.authenticate(
url: fullUrl.toString(),
callbackUrlScheme: 'appwrite-callback-${AppwriteConstants.projectId}',
options: const FlutterWebAuth2Options(preferEphemeral: true),
);
final url = Uri.parse(responseUrl);
final secret = url.queryParameters['secret'];
if (secret == null) throw Exception('Invalid response from OAuth');
onSuccessCallback(secret);
} on PlatformException catch (e, st) {
if (e.code == 'CANCELED') return;
onFailureCallback(e, st);
} catch (e, st) {
onFailureCallback(e, st);
}
},
child: const Text('Sign in With Apple'),
);