forwardRedirect function
Future<String?>
forwardRedirect( - dynamic context,
- dynamic state
)
Implementation
Future<String?> forwardRedirect(
BuildContext context,
GoRouterState state,
) async {
try {
final acterSdk = await ActerSdk.instance;
if (!acterSdk.hasClients) {
// we are not logged in.
return null;
}
Client client;
try {
final deviceId = state.uri.queryParameters['deviceId'];
client = await acterSdk.getClientWithDeviceId(deviceId!, true);
// ignore: use_build_context_synchronously
final ref = ProviderScope.containerOf(context);
// ensure we have selected the right client
ref.invalidate(clientProvider);
} catch (e, s) {
_log.severe('Client not found', e, s);
return null;
}
final roomId = state.uri.queryParameters['roomId'];
if (await client.hasConvo(roomId!)) {
// this is a chat
return state.namedLocation(
Routes.chatroom.name,
pathParameters: {'roomId': roomId},
);
} else {
// final eventId = state.uri.queryParameters['eventId'];
// with the event ID or further information we could figure out the specific action
return state.namedLocation(
Routes.space.name,
pathParameters: {'spaceId': roomId},
);
}
} catch (e, s) {
_log.severe('Forward fail', e, s);
return state.namedLocation(
Routes.fatalFail.name,
queryParameters: {'error': e.toString(), 'trace': s.toString()},
);
}
}