mirror of
https://github.com/foss42/apidash.git
synced 2025-08-18 17:34:18 +08:00

Moved dark mode color blending logic to a Color extension (toDark) in the design system. Updated usages in ui_utils.dart and related tests to use the new extension. Removed the old getDarkModeColor function for cleaner and more idiomatic code organization.
77 lines
1.7 KiB
Dart
77 lines
1.7 KiB
Dart
import 'package:apidash_core/apidash_core.dart';
|
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../consts.dart';
|
|
|
|
Color getResponseStatusCodeColor(int? statusCode,
|
|
{Brightness brightness = Brightness.light}) {
|
|
Color col = kColorStatusCodeDefault;
|
|
if (statusCode != null) {
|
|
if (statusCode >= 200) {
|
|
col = kColorStatusCode200;
|
|
}
|
|
if (statusCode >= 300) {
|
|
col = kColorStatusCode300;
|
|
}
|
|
if (statusCode >= 400) {
|
|
col = kColorStatusCode400;
|
|
}
|
|
if (statusCode >= 500) {
|
|
col = kColorStatusCode500;
|
|
}
|
|
}
|
|
if (brightness == Brightness.dark) {
|
|
col = col.toDark;
|
|
}
|
|
return col;
|
|
}
|
|
|
|
Color getAPIColor(
|
|
APIType apiType, {
|
|
HTTPVerb? method,
|
|
Brightness? brightness,
|
|
}) {
|
|
Color col = switch (apiType) {
|
|
APIType.rest => getHTTPMethodColor(
|
|
method,
|
|
),
|
|
APIType.graphql => kColorGQL,
|
|
};
|
|
if (brightness == Brightness.dark) {
|
|
col = col.toDark;
|
|
}
|
|
return col;
|
|
}
|
|
|
|
Color getHTTPMethodColor(HTTPVerb? method) {
|
|
Color col = switch (method) {
|
|
HTTPVerb.get => kColorHttpMethodGet,
|
|
HTTPVerb.head => kColorHttpMethodHead,
|
|
HTTPVerb.post => kColorHttpMethodPost,
|
|
HTTPVerb.put => kColorHttpMethodPut,
|
|
HTTPVerb.patch => kColorHttpMethodPatch,
|
|
HTTPVerb.delete => kColorHttpMethodDelete,
|
|
HTTPVerb.options => kColorHttpMethodOptions,
|
|
_ => kColorHttpMethodGet,
|
|
};
|
|
return col;
|
|
}
|
|
|
|
double? getJsonPreviewerMaxRootNodeWidth(double w) {
|
|
if (w < 300) {
|
|
return 150;
|
|
}
|
|
if (w < 400) {
|
|
return 200;
|
|
}
|
|
return w - 150;
|
|
}
|
|
|
|
GlobalKey<ScaffoldState> getScaffoldKey(int railIdx) {
|
|
return switch (railIdx) {
|
|
1 => kEnvScaffoldKey,
|
|
2 => kHisScaffoldKey,
|
|
_ => kHomeScaffoldKey,
|
|
};
|
|
}
|