mirror of
https://github.com/foss42/apidash.git
synced 2025-05-30 05:21:15 +08:00
add feature 22
This commit is contained in:
@ -18,6 +18,8 @@ class _EditRequestBodyState extends ConsumerState<EditRequestBody> {
|
|||||||
final requestModel = ref
|
final requestModel = ref
|
||||||
.read(collectionStateNotifierProvider.notifier)
|
.read(collectionStateNotifierProvider.notifier)
|
||||||
.getRequestModel(activeId!);
|
.getRequestModel(activeId!);
|
||||||
|
final contentType = ref.watch(activeRequestModelProvider
|
||||||
|
.select((value) => value?.requestBodyContentType));
|
||||||
return Container(
|
return Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.background,
|
color: Theme.of(context).colorScheme.background,
|
||||||
@ -39,6 +41,7 @@ class _EditRequestBodyState extends ConsumerState<EditRequestBody> {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextFieldEditor(
|
child: TextFieldEditor(
|
||||||
|
contentType: contentType,
|
||||||
key: Key("$activeId-body"),
|
key: Key("$activeId-body"),
|
||||||
fieldKey: "$activeId-body-editor",
|
fieldKey: "$activeId-body-editor",
|
||||||
initialValue: requestModel?.requestBody,
|
initialValue: requestModel?.requestBody,
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:math' as math;
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'package:json_text_field/json_text_field.dart';
|
||||||
|
|
||||||
class TextFieldEditor extends StatefulWidget {
|
class TextFieldEditor extends StatefulWidget {
|
||||||
const TextFieldEditor({
|
const TextFieldEditor({
|
||||||
@ -9,21 +10,23 @@ class TextFieldEditor extends StatefulWidget {
|
|||||||
required this.fieldKey,
|
required this.fieldKey,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.initialValue,
|
this.initialValue,
|
||||||
|
this.contentType,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String fieldKey;
|
final String fieldKey;
|
||||||
final Function(String)? onChanged;
|
final Function(String)? onChanged;
|
||||||
final String? initialValue;
|
final String? initialValue;
|
||||||
|
final ContentType? contentType;
|
||||||
@override
|
@override
|
||||||
State<TextFieldEditor> createState() => _TextFieldEditorState();
|
State<TextFieldEditor> createState() => _TextFieldEditorState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TextFieldEditorState extends State<TextFieldEditor> {
|
class _TextFieldEditorState extends State<TextFieldEditor> {
|
||||||
final TextEditingController controller = TextEditingController();
|
final JsonTextFieldController controller = JsonTextFieldController();
|
||||||
late final FocusNode editorFocusNode;
|
late final FocusNode editorFocusNode;
|
||||||
|
|
||||||
void insertTab() {
|
void insertTab() {
|
||||||
String sp = " ";
|
String sp = " ";
|
||||||
int offset = math.min(
|
int offset = math.min(
|
||||||
controller.selection.baseOffset, controller.selection.extentOffset);
|
controller.selection.baseOffset, controller.selection.extentOffset);
|
||||||
String text = controller.text.substring(0, offset) +
|
String text = controller.text.substring(0, offset) +
|
||||||
@ -42,6 +45,9 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
if (widget.contentType == ContentType.json) {
|
||||||
|
controller.formatJson(sortJson: false);
|
||||||
|
}
|
||||||
editorFocusNode = FocusNode(debugLabel: "Editor Focus Node");
|
editorFocusNode = FocusNode(debugLabel: "Editor Focus Node");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +68,22 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
|
|||||||
insertTab();
|
insertTab();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
child: TextFormField(
|
child: JsonTextField(
|
||||||
|
stringHighlightStyle: kCodeStyle.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
),
|
||||||
|
keyHighlightStyle: kCodeStyle.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
errorContainerDecoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.error.withOpacity(
|
||||||
|
kForegroundOpacity,
|
||||||
|
),
|
||||||
|
borderRadius: kBorderRadius8,
|
||||||
|
),
|
||||||
|
showErrorMessage: true,
|
||||||
|
isFormatting: widget.contentType == ContentType.json,
|
||||||
key: Key(widget.fieldKey),
|
key: Key(widget.fieldKey),
|
||||||
controller: controller,
|
controller: controller,
|
||||||
focusNode: editorFocusNode,
|
focusNode: editorFocusNode,
|
||||||
@ -71,7 +92,12 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
|
|||||||
maxLines: null,
|
maxLines: null,
|
||||||
style: kCodeStyle,
|
style: kCodeStyle,
|
||||||
textAlignVertical: TextAlignVertical.top,
|
textAlignVertical: TextAlignVertical.top,
|
||||||
onChanged: widget.onChanged,
|
onChanged: (value) {
|
||||||
|
widget.onChanged?.call(value);
|
||||||
|
if (widget.contentType == ContentType.json) {
|
||||||
|
controller.formatJson(sortJson: false);
|
||||||
|
}
|
||||||
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: "Enter content (body)",
|
hintText: "Enter content (body)",
|
||||||
hintStyle: TextStyle(
|
hintStyle: TextStyle(
|
||||||
|
28
pubspec.lock
28
pubspec.lock
@ -241,6 +241,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.1"
|
version: "1.0.1"
|
||||||
|
extended_text_field:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: extended_text_field
|
||||||
|
sha256: ed9655c70a47a54c7cc689cf7f89a2bde9ab7b530150b4d1808b7aa7eb8cdf90
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "13.0.0"
|
||||||
|
extended_text_library:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: extended_text_library
|
||||||
|
sha256: "55d09098ec56fab0d9a8a68950ca0bbf2efa1327937f7cec6af6dfa066234829"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "12.0.0"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -537,6 +553,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.7.1"
|
version: "6.7.1"
|
||||||
|
json_text_field:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: json_text_field
|
||||||
|
sha256: caec2d687221746f81503a0cfad263d349ecb3d538dd518b820beafc32f1dfce
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
just_audio:
|
just_audio:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -1248,5 +1272,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.2"
|
version: "3.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.2.0-194.0.dev <4.0.0"
|
dart: ">=3.2.0 <4.0.0"
|
||||||
flutter: ">=3.13.0"
|
flutter: ">=3.16.0"
|
||||||
|
@ -10,6 +10,7 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
multi_split_view: ^2.4.0
|
multi_split_view: ^2.4.0
|
||||||
url_launcher: ^6.1.12
|
url_launcher: ^6.1.12
|
||||||
flutter_riverpod: ^2.3.7
|
flutter_riverpod: ^2.3.7
|
||||||
@ -46,8 +47,9 @@ dependencies:
|
|||||||
json_data_explorer:
|
json_data_explorer:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/foss42/json_data_explorer.git
|
url: https://github.com/foss42/json_data_explorer.git
|
||||||
version: ^0.1.1
|
version: ^0.1.1
|
||||||
scrollable_positioned_list: ^0.2.3
|
scrollable_positioned_list: ^0.2.3
|
||||||
|
json_text_field: ^1.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user