customGoNamed method
void
customGoNamed(})
Implementation
void customGoNamed(String routeName, {Map<String, String> params = const {}, bool replaceRouteName = false, String? replacedRouteName}) {
Map<String, String> extraParam = {};
if (replacedRouteName != null) {
if (replaceRouteName) {
extraParam.addAll({"routeName": replacedRouteName});
} else {
extraParam.addAll({"routeName": "$routeName $replacedRouteName"});
}
}
// Controlla se non è desktop e se esiste uno Scaffold
if (!ResponsiveBreakpoints.of(this).isDesktop) {
final scaffold = Scaffold.maybeOf(this);
if (scaffold != null && scaffold.isDrawerOpen) {
scaffold.closeDrawer();
}
}
// Cerca il path dal RouteRegistry usando il nome
final registry = RouteRegistry();
// Passa il path corrente come contesto per aiutare a scegliere la route corretta
final currentPath = GoRouterState.of(this).uri.path;
final String? fullPath = registry.getPathByName(routeName, contextPath: currentPath);
if (fullPath != null) {
// Sostituisci i parametri nel path
String processedPath = fullPath;
params.forEach((key, value) {
processedPath = processedPath.replaceAll(':$key', value);
});
go(processedPath, extra: extraParam);
} else {
// Fallback al comportamento originale se la route non è trovata
goNamed(routeName, extra: extraParam, pathParameters: params);
}
}