mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
feat: create a dedicated provider for dashbot navigation
This commit is contained in:
22
lib/dashbot/core/utils/dashbot_route_utils.dart
Normal file
22
lib/dashbot/core/utils/dashbot_route_utils.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:apidash/models/models.dart';
|
||||
|
||||
import '../routes/dashbot_routes.dart';
|
||||
|
||||
/// Computes the base Dashbot route for a given request based on whether a
|
||||
/// response exists.
|
||||
/// - Returns [DashbotRoutes.dashbotHome] if the request has a response (either
|
||||
/// statusCode or responseStatus present).
|
||||
/// - Otherwise returns [DashbotRoutes.dashbotDefault].
|
||||
String computeDashbotBaseRoute(RequestModel? req) {
|
||||
final hasResponse = (req?.httpResponseModel?.statusCode != null) ||
|
||||
(req?.responseStatus != null);
|
||||
return hasResponse ? DashbotRoutes.dashbotHome : DashbotRoutes.dashbotDefault;
|
||||
}
|
||||
|
||||
/// Returns true if the route that should be shown for [req] differs from the
|
||||
/// currently active [currentRoute].
|
||||
/// This helper is pure and does not perform any side effects.
|
||||
bool needsDashbotRouteChange(RequestModel? req, String currentRoute) {
|
||||
final target = computeDashbotBaseRoute(req);
|
||||
return target != currentRoute;
|
||||
}
|
||||
Reference in New Issue
Block a user