add feature 22

This commit is contained in:
Antonio Jesus Caballero Encinas
2023-12-21 11:55:24 +01:00
parent 114f5073f9
commit aabed77f76
4 changed files with 62 additions and 7 deletions

View File

@ -18,6 +18,8 @@ class _EditRequestBodyState extends ConsumerState<EditRequestBody> {
final requestModel = ref
.read(collectionStateNotifierProvider.notifier)
.getRequestModel(activeId!);
final contentType = ref.watch(activeRequestModelProvider
.select((value) => value?.requestBodyContentType));
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
@ -39,6 +41,7 @@ class _EditRequestBodyState extends ConsumerState<EditRequestBody> {
),
Expanded(
child: TextFieldEditor(
contentType: contentType,
key: Key("$activeId-body"),
fieldKey: "$activeId-body-editor",
initialValue: requestModel?.requestBody,

View File

@ -2,6 +2,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:apidash/consts.dart';
import 'package:json_text_field/json_text_field.dart';
class TextFieldEditor extends StatefulWidget {
const TextFieldEditor({
@ -9,17 +10,19 @@ class TextFieldEditor extends StatefulWidget {
required this.fieldKey,
this.onChanged,
this.initialValue,
this.contentType,
});
final String fieldKey;
final Function(String)? onChanged;
final String? initialValue;
final ContentType? contentType;
@override
State<TextFieldEditor> createState() => _TextFieldEditorState();
}
class _TextFieldEditorState extends State<TextFieldEditor> {
final TextEditingController controller = TextEditingController();
final JsonTextFieldController controller = JsonTextFieldController();
late final FocusNode editorFocusNode;
void insertTab() {
@ -42,6 +45,9 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
@override
void initState() {
super.initState();
if (widget.contentType == ContentType.json) {
controller.formatJson(sortJson: false);
}
editorFocusNode = FocusNode(debugLabel: "Editor Focus Node");
}
@ -62,7 +68,22 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
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),
controller: controller,
focusNode: editorFocusNode,
@ -71,7 +92,12 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
maxLines: null,
style: kCodeStyle,
textAlignVertical: TextAlignVertical.top,
onChanged: widget.onChanged,
onChanged: (value) {
widget.onChanged?.call(value);
if (widget.contentType == ContentType.json) {
controller.formatJson(sortJson: false);
}
},
decoration: InputDecoration(
hintText: "Enter content (body)",
hintStyle: TextStyle(

View File

@ -241,6 +241,22 @@ packages:
url: "https://pub.dev"
source: hosted
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:
dependency: transitive
description:
@ -537,6 +553,14 @@ packages:
url: "https://pub.dev"
source: hosted
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:
dependency: "direct main"
description:
@ -1248,5 +1272,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.13.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"

View File

@ -10,6 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
multi_split_view: ^2.4.0
url_launcher: ^6.1.12
flutter_riverpod: ^2.3.7
@ -48,6 +49,7 @@ dependencies:
url: https://github.com/foss42/json_data_explorer.git
version: ^0.1.1
scrollable_positioned_list: ^0.2.3
json_text_field: ^1.0.0
dev_dependencies:
flutter_test: