mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 04:50:36 +08:00
85 lines
1.8 KiB
Dart
85 lines
1.8 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 = getDarkModeColor(col);
|
|
}
|
|
return col;
|
|
}
|
|
|
|
Color getHTTPMethodColor(HTTPVerb method,
|
|
{Brightness brightness = Brightness.light}) {
|
|
Color col;
|
|
switch (method) {
|
|
case HTTPVerb.get:
|
|
col = kColorHttpMethodGet;
|
|
break;
|
|
case HTTPVerb.head:
|
|
col = kColorHttpMethodHead;
|
|
break;
|
|
case HTTPVerb.post:
|
|
col = kColorHttpMethodPost;
|
|
break;
|
|
case HTTPVerb.put:
|
|
col = kColorHttpMethodPut;
|
|
break;
|
|
case HTTPVerb.patch:
|
|
col = kColorHttpMethodPatch;
|
|
break;
|
|
case HTTPVerb.delete:
|
|
col = kColorHttpMethodDelete;
|
|
break;
|
|
}
|
|
if (brightness == Brightness.dark) {
|
|
col = getDarkModeColor(col);
|
|
}
|
|
return col;
|
|
}
|
|
|
|
Color getDarkModeColor(Color col) {
|
|
return Color.alphaBlend(
|
|
col.withOpacity(kOpacityDarkModeBlend),
|
|
kColorWhite,
|
|
);
|
|
}
|
|
|
|
double? getJsonPreviewerMaxRootNodeWidth(double w) {
|
|
if (w < 300) {
|
|
return 150;
|
|
}
|
|
if (w < 400) {
|
|
return 200;
|
|
}
|
|
return w - 150;
|
|
}
|
|
|
|
GlobalKey<ScaffoldState> getScaffoldKey(int railIdx) {
|
|
switch (railIdx) {
|
|
case 1:
|
|
return kEnvScaffoldKey;
|
|
case 2:
|
|
return kHisScaffoldKey;
|
|
default:
|
|
return kHomeScaffoldKey;
|
|
}
|
|
}
|