mirror of
https://github.com/foss42/apidash.git
synced 2025-06-02 16:02:12 +08:00
Fix: Header Field
This commit is contained in:
@ -33,9 +33,7 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final activeId = ref.watch(activeIdStateProvider);
|
final activeId = ref.read(activeIdStateProvider);
|
||||||
final length = ref.watch(activeRequestModelProvider
|
|
||||||
.select((value) => value?.requestHeaders?.length));
|
|
||||||
var rH = ref.read(activeRequestModelProvider)?.requestHeaders;
|
var rH = ref.read(activeRequestModelProvider)?.requestHeaders;
|
||||||
rows = (rH == null || rH.isEmpty)
|
rows = (rH == null || rH.isEmpty)
|
||||||
? [
|
? [
|
||||||
@ -51,16 +49,13 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
|
|||||||
grow: 1,
|
grow: 1,
|
||||||
cellBuilder: (_, row) {
|
cellBuilder: (_, row) {
|
||||||
int idx = row.index;
|
int idx = row.index;
|
||||||
TextEditingController headerController =
|
|
||||||
TextEditingController(text: rows[idx].name);
|
|
||||||
return HeaderField(
|
return HeaderField(
|
||||||
keyId: "$activeId-$idx-headers-k-$seed",
|
keyId: "$activeId-$idx-headers-k-$seed",
|
||||||
controller: headerController,
|
initialValue: rows[idx].name,
|
||||||
hintText: "Add Header Name",
|
hintText: "Add Header Name",
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
rows[idx] = rows[idx].copyWith(name: value);
|
rows[idx] = rows[idx].copyWith(name: value);
|
||||||
_onFieldChange(activeId!);
|
_onFieldChange(activeId!);
|
||||||
headerController.text = value;
|
|
||||||
},
|
},
|
||||||
colorScheme: Theme.of(context).colorScheme,
|
colorScheme: Theme.of(context).colorScheme,
|
||||||
);
|
);
|
||||||
|
@ -7,14 +7,14 @@ class HeaderField extends StatefulWidget {
|
|||||||
const HeaderField({
|
const HeaderField({
|
||||||
super.key,
|
super.key,
|
||||||
required this.keyId,
|
required this.keyId,
|
||||||
required this.controller,
|
|
||||||
this.hintText,
|
this.hintText,
|
||||||
|
this.initialValue,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.colorScheme,
|
this.colorScheme,
|
||||||
});
|
});
|
||||||
final TextEditingController controller;
|
|
||||||
final String keyId;
|
final String keyId;
|
||||||
final String? hintText;
|
final String? hintText;
|
||||||
|
final String? initialValue;
|
||||||
final void Function(String)? onChanged;
|
final void Function(String)? onChanged;
|
||||||
final ColorScheme? colorScheme;
|
final ColorScheme? colorScheme;
|
||||||
|
|
||||||
@ -23,25 +23,42 @@ class HeaderField extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HeaderFieldState extends State<HeaderField> {
|
class _HeaderFieldState extends State<HeaderField> {
|
||||||
|
late TextEditingController controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
controller = TextEditingController(text: widget.initialValue);
|
||||||
|
controller.selection =
|
||||||
|
TextSelection.collapsed(offset: controller.text.length);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var colorScheme = widget.colorScheme ?? Theme.of(context).colorScheme;
|
var colorScheme = widget.colorScheme ?? Theme.of(context).colorScheme;
|
||||||
return TypeAheadFormField(
|
return TypeAheadField(
|
||||||
minCharsForSuggestions: 1,
|
|
||||||
hideOnEmpty: true,
|
|
||||||
key: Key(widget.keyId),
|
key: Key(widget.keyId),
|
||||||
onSuggestionSelected: widget.onChanged!,
|
hideOnEmpty: true,
|
||||||
|
minCharsForSuggestions: 1,
|
||||||
|
onSuggestionSelected: (value) {
|
||||||
|
setState(() {
|
||||||
|
controller.text = value;
|
||||||
|
});
|
||||||
|
widget.onChanged!.call(value);
|
||||||
|
},
|
||||||
itemBuilder: (context, String suggestion) {
|
itemBuilder: (context, String suggestion) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
dense: true,
|
dense: true,
|
||||||
title: Text(suggestion),
|
title: Text(suggestion),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
suggestionsCallback: getHeaderSuggestions,
|
suggestionsCallback: headerSuggestionCallback,
|
||||||
suggestionsBoxDecoration: suggestionBoxDecorations(context),
|
suggestionsBoxDecoration: suggestionBoxDecorations(context),
|
||||||
textFieldConfiguration: TextFieldConfiguration(
|
textFieldConfiguration: TextFieldConfiguration(
|
||||||
onChanged: widget.onChanged!,
|
onChanged: (s) {
|
||||||
controller: widget.controller,
|
widget.onChanged?.call(s);
|
||||||
|
},
|
||||||
|
controller: controller,
|
||||||
style: kCodeStyle.copyWith(
|
style: kCodeStyle.copyWith(
|
||||||
color: colorScheme.onSurface,
|
color: colorScheme.onSurface,
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user