mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
feat: replace DropdownButtonFormField with ADPopupMenu for improved UI consistency
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:apidash/screens/common_widgets/auth_textfield.dart';
|
|||||||
import 'package:apidash_core/consts.dart';
|
import 'package:apidash_core/consts.dart';
|
||||||
import 'package:apidash_core/models/auth/api_auth_model.dart';
|
import 'package:apidash_core/models/auth/api_auth_model.dart';
|
||||||
import 'package:apidash_core/models/auth/auth_api_key_model.dart';
|
import 'package:apidash_core/models/auth/auth_api_key_model.dart';
|
||||||
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ApiKeyAuthFields extends StatefulWidget {
|
class ApiKeyAuthFields extends StatefulWidget {
|
||||||
@@ -40,35 +41,26 @@ class _ApiKeyAuthFieldsState extends State<ApiKeyAuthFields> {
|
|||||||
Text(
|
Text(
|
||||||
"Add to",
|
"Add to",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 4,
|
height: 4,
|
||||||
),
|
),
|
||||||
DropdownButtonFormField<String>(
|
ADPopupMenu<String>(
|
||||||
value: _addKeyTo,
|
value: _addKeyTo == 'header' ? 'Header' : 'Query Params',
|
||||||
decoration: InputDecoration(
|
values: const [
|
||||||
constraints: BoxConstraints(
|
('header', 'Header'),
|
||||||
maxWidth: MediaQuery.sizeOf(context).width - 100,
|
('query', 'Query Params'),
|
||||||
),
|
|
||||||
contentPadding: const EdgeInsets.all(18),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 'header',
|
|
||||||
child: Text('Header'),
|
|
||||||
),
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 'query',
|
|
||||||
child: Text('Query Params'),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
|
tooltip: "Select where to add API key",
|
||||||
|
isOutlined: true,
|
||||||
onChanged: (String? newLocation) {
|
onChanged: (String? newLocation) {
|
||||||
if (newLocation != null) {
|
if (newLocation != null) {
|
||||||
|
setState(() {
|
||||||
|
_addKeyTo = newLocation;
|
||||||
|
});
|
||||||
_updateApiKeyAuth();
|
_updateApiKeyAuth();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -82,7 +74,7 @@ class _ApiKeyAuthFieldsState extends State<ApiKeyAuthFields> {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
AuthTextField(
|
AuthTextField(
|
||||||
controller: _keyController,
|
controller: _keyController,
|
||||||
hintText: "API KeyName",
|
hintText: "API Key",
|
||||||
isObscureText: true,
|
isObscureText: true,
|
||||||
onChanged: (value) => _updateApiKeyAuth(),
|
onChanged: (value) => _updateApiKeyAuth(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:apidash/screens/common_widgets/auth_textfield.dart';
|
import 'package:apidash/screens/common_widgets/auth_textfield.dart';
|
||||||
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:apidash_core/apidash_core.dart';
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
|
|
||||||
@@ -42,33 +43,25 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
|
|||||||
Text(
|
Text(
|
||||||
"Add JWT token to",
|
"Add JWT token to",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
DropdownButtonFormField<String>(
|
ADPopupMenu<String>(
|
||||||
value: _addTokenTo,
|
value:
|
||||||
decoration: InputDecoration(
|
_addTokenTo == 'header' ? 'Request Header' : 'Query Parameters',
|
||||||
constraints: BoxConstraints(
|
values: const [
|
||||||
maxWidth: MediaQuery.sizeOf(context).width - 100,
|
('header', 'Request Header'),
|
||||||
),
|
('query', 'Query Parameters'),
|
||||||
contentPadding: const EdgeInsets.all(18),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 'header',
|
|
||||||
child: Text('Request Header'),
|
|
||||||
),
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 'query',
|
|
||||||
child: Text('Query Parameters'),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
|
tooltip: "Select where to add JWT token",
|
||||||
|
isOutlined: true,
|
||||||
onChanged: (String? newAddTokenTo) {
|
onChanged: (String? newAddTokenTo) {
|
||||||
if (newAddTokenTo != null) {
|
if (newAddTokenTo != null) {
|
||||||
|
setState(() {
|
||||||
|
_addTokenTo = newAddTokenTo;
|
||||||
|
});
|
||||||
_updateJwtAuth();
|
_updateJwtAuth();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -77,33 +70,25 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
|
|||||||
Text(
|
Text(
|
||||||
"Algorithm",
|
"Algorithm",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
DropdownButtonFormField<String>(
|
ADPopupMenu<String>(
|
||||||
value: _algorithm,
|
value: _algorithm,
|
||||||
decoration: InputDecoration(
|
values: const [
|
||||||
constraints: BoxConstraints(
|
('HS256', 'HS256'),
|
||||||
maxWidth: MediaQuery.sizeOf(context).width - 100,
|
('HS384', 'HS384'),
|
||||||
),
|
('HS512', 'HS512'),
|
||||||
contentPadding: const EdgeInsets.all(18),
|
],
|
||||||
border: OutlineInputBorder(
|
tooltip: "Select JWT algorithm",
|
||||||
borderRadius: BorderRadius.circular(8),
|
isOutlined: true,
|
||||||
),
|
|
||||||
),
|
|
||||||
items: [
|
|
||||||
'HS256',
|
|
||||||
'HS384',
|
|
||||||
'HS512',
|
|
||||||
].map((algorithm) {
|
|
||||||
return DropdownMenuItem(
|
|
||||||
value: algorithm,
|
|
||||||
child: Text(algorithm),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
onChanged: (String? newAlgorithm) {
|
onChanged: (String? newAlgorithm) {
|
||||||
if (newAlgorithm != null) {
|
if (newAlgorithm != null) {
|
||||||
|
setState(() {
|
||||||
|
_algorithm = newAlgorithm;
|
||||||
|
});
|
||||||
_updateJwtAuth();
|
_updateJwtAuth();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -120,7 +105,8 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
|
|||||||
title: Text(
|
title: Text(
|
||||||
"Secret is Base64 encoded",
|
"Secret is Base64 encoded",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
value: _isSecretBase64Encoded,
|
value: _isSecretBase64Encoded,
|
||||||
@@ -138,7 +124,8 @@ class _JwtAuthFieldsState extends State<JwtAuthFields> {
|
|||||||
Text(
|
Text(
|
||||||
"Payload (JSON format)",
|
"Payload (JSON format)",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ class _AuthFieldState extends State<AuthTextField> {
|
|||||||
Text(
|
Text(
|
||||||
widget.hintText,
|
widget.hintText,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:apidash/screens/common_widgets/auth/api_key_auth_fields.dart';
|
|||||||
import 'package:apidash/screens/common_widgets/auth/basic_auth_fields.dart';
|
import 'package:apidash/screens/common_widgets/auth/basic_auth_fields.dart';
|
||||||
import 'package:apidash/screens/common_widgets/auth/bearer_auth_fields.dart';
|
import 'package:apidash/screens/common_widgets/auth/bearer_auth_fields.dart';
|
||||||
import 'package:apidash/screens/common_widgets/auth/jwt_auth_fields.dart';
|
import 'package:apidash/screens/common_widgets/auth/jwt_auth_fields.dart';
|
||||||
|
import 'package:apidash_design_system/widgets/popup_menu.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:apidash_core/apidash_core.dart';
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
@@ -39,20 +40,20 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
DropdownButtonFormField<APIAuthType>(
|
ADPopupMenu<APIAuthType>(
|
||||||
value: currentAuthType,
|
value: currentAuthType.name.capitalize(),
|
||||||
elevation: 4,
|
values: const [
|
||||||
decoration: InputDecoration(
|
(APIAuthType.none, 'None'),
|
||||||
border: OutlineInputBorder(
|
(APIAuthType.basic, 'Basic'),
|
||||||
borderRadius: BorderRadius.circular(9),
|
(APIAuthType.apiKey, 'API Key'),
|
||||||
),
|
(APIAuthType.bearer, 'Bearer'),
|
||||||
),
|
(APIAuthType.jwt, 'JWT'),
|
||||||
items: APIAuthType.values.map((type) {
|
(APIAuthType.digest, 'Digest'),
|
||||||
return DropdownMenuItem(
|
(APIAuthType.oauth1, 'OAuth 1.0'),
|
||||||
value: type,
|
(APIAuthType.oauth2, 'OAuth 2.0'),
|
||||||
child: Text(type.name.capitalize()),
|
],
|
||||||
);
|
tooltip: "Select Authentication Type",
|
||||||
}).toList(),
|
isOutlined: true,
|
||||||
onChanged: (APIAuthType? newType) {
|
onChanged: (APIAuthType? newType) {
|
||||||
final selectedRequest = ref.read(selectedRequestModelProvider);
|
final selectedRequest = ref.read(selectedRequestModelProvider);
|
||||||
if (newType != null) {
|
if (newType != null) {
|
||||||
@@ -72,6 +73,7 @@ class EditAuthType extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ...existing code...
|
||||||
Widget _buildAuthFields(
|
Widget _buildAuthFields(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
|
|||||||
Reference in New Issue
Block a user