diff --git a/lib/utils/ui_utils.dart b/lib/utils/ui_utils.dart index 9f4c6a64..23d908a7 100644 --- a/lib/utils/ui_utils.dart +++ b/lib/utils/ui_utils.dart @@ -28,27 +28,14 @@ Color getResponseStatusCodeColor(int? statusCode, 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; - } + Color col = switch (method) { + HTTPVerb.get => kColorHttpMethodGet, + HTTPVerb.head => kColorHttpMethodHead, + HTTPVerb.post => kColorHttpMethodPost, + HTTPVerb.put => kColorHttpMethodPut, + HTTPVerb.patch => kColorHttpMethodPatch, + HTTPVerb.delete => kColorHttpMethodDelete, + }; if (brightness == Brightness.dark) { col = getDarkModeColor(col); } @@ -73,12 +60,9 @@ double? getJsonPreviewerMaxRootNodeWidth(double w) { } GlobalKey getScaffoldKey(int railIdx) { - switch (railIdx) { - case 1: - return kEnvScaffoldKey; - case 2: - return kHisScaffoldKey; - default: - return kHomeScaffoldKey; - } + return switch (railIdx) { + 1 => kEnvScaffoldKey, + 2 => kHisScaffoldKey, + _ => kHomeScaffoldKey, + }; } diff --git a/lib/widgets/texts.dart b/lib/widgets/texts.dart index 1db15516..dad5e0ce 100644 --- a/lib/widgets/texts.dart +++ b/lib/widgets/texts.dart @@ -4,22 +4,18 @@ import 'package:flutter/material.dart'; import 'package:apidash/utils/utils.dart'; class MethodBox extends StatelessWidget { - const MethodBox({super.key, required this.method}); + const MethodBox({ + super.key, + required this.method, + }); final HTTPVerb method; @override Widget build(BuildContext context) { - String text = method.name.toUpperCase(); - if (method == HTTPVerb.delete) { - text = "DEL"; - } - if (method == HTTPVerb.patch) { - text = "PAT"; - } return SizedBox( width: 24, child: Text( - text, + method.abbr, textAlign: TextAlign.center, style: TextStyle( fontSize: 8, diff --git a/packages/apidash_core/lib/consts.dart b/packages/apidash_core/lib/consts.dart index dbee507c..c17ec451 100644 --- a/packages/apidash_core/lib/consts.dart +++ b/packages/apidash_core/lib/consts.dart @@ -7,7 +7,17 @@ enum APIType { final String label; } -enum HTTPVerb { get, head, post, put, patch, delete } +enum HTTPVerb { + get("GET"), + head("HEAD"), + post("POST"), + put("PUT"), + patch("PAT"), + delete("DEL"); + + const HTTPVerb(this.abbr); + final String abbr; +} enum SupportedUriSchemes { https, http }