createSecureRedirectUrl function
Creates a secure URL for the WebView with the token parameters
Implementation
String createSecureRedirectUrl(String fi, String reqdate, String ecreq, {String? theme}) {
// Use the current environment's URL
final String baseUrl = SaafeSdk.baseRedirectUrl;
final Uri url = Uri.parse(baseUrl);
// Add the required query parameters, only if they're not empty
final Map<String, String> queryParams = {};
if (fi.isNotEmpty) queryParams['fi'] = fi;
if (reqdate.isNotEmpty) queryParams['reqdate'] = reqdate;
if (ecreq.isNotEmpty) queryParams['ecreq'] = ecreq;
// Add platform flag
if (Platform.isIOS) {
queryParams['platform'] = 'ios';
} else if (Platform.isAndroid) {
queryParams['platform'] = 'android';
} else {
queryParams['platform'] = 'flutter';
}
// Add theme flag if provided, otherwise use system
if (theme != null && (theme == 'light' || theme == 'dark')) {
queryParams['theme'] = theme;
} else {
// Get system theme
final Brightness systemBrightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
queryParams['theme'] = systemBrightness == Brightness.dark ? 'dark' : 'light';
}
// Log if parameters are empty
if (queryParams.isEmpty || (fi.isEmpty || reqdate.isEmpty || ecreq.isEmpty)) {
debugPrint("SAAFE SDK Warning: Some or all parameters are empty. This will result in an incomplete URL.");
}
final String finalUrl = url.replace(queryParameters: queryParams).toString();
return finalUrl;
}