closeModalInUri static method
Implementation
@visibleForTesting
static Uri closeModalInUri(Uri currentUri, String modalId) {
final currentModals = _getCurrentModals(currentUri);
if (!currentModals.contains(modalId)) {
return currentUri;
}
final updatedModals = List<String>.from(currentModals)..remove(modalId);
final updatedQueryParams = <String, String>{
for (final entry in currentUri.queryParameters.entries)
if (entry.key != 'modal') entry.key: entry.value,
};
if (updatedModals.isNotEmpty) {
updatedQueryParams['modal'] = updatedModals.join(',');
}
final currentModalParam = currentUri.queryParameters['modal'];
final newModalParam = updatedModals.isEmpty ? null : updatedModals.join(',');
if (currentModalParam == newModalParam) {
return currentUri;
}
return Uri(
path: currentUri.path,
queryParameters: updatedQueryParams.isEmpty ? null : updatedQueryParams,
fragment: currentUri.fragment,
);
}