Fix: Header Field

This commit is contained in:
DenserMeerkat
2023-10-20 17:26:32 +05:30
parent d2e0ca9967
commit 3af7dea19a
2 changed files with 28 additions and 16 deletions

View File

@ -33,9 +33,7 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
@override
Widget build(BuildContext context) {
final activeId = ref.watch(activeIdStateProvider);
final length = ref.watch(activeRequestModelProvider
.select((value) => value?.requestHeaders?.length));
final activeId = ref.read(activeIdStateProvider);
var rH = ref.read(activeRequestModelProvider)?.requestHeaders;
rows = (rH == null || rH.isEmpty)
? [
@ -51,16 +49,13 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
grow: 1,
cellBuilder: (_, row) {
int idx = row.index;
TextEditingController headerController =
TextEditingController(text: rows[idx].name);
return HeaderField(
keyId: "$activeId-$idx-headers-k-$seed",
controller: headerController,
initialValue: rows[idx].name,
hintText: "Add Header Name",
onChanged: (value) {
rows[idx] = rows[idx].copyWith(name: value);
_onFieldChange(activeId!);
headerController.text = value;
},
colorScheme: Theme.of(context).colorScheme,
);

View File

@ -7,14 +7,14 @@ class HeaderField extends StatefulWidget {
const HeaderField({
super.key,
required this.keyId,
required this.controller,
this.hintText,
this.initialValue,
this.onChanged,
this.colorScheme,
});
final TextEditingController controller;
final String keyId;
final String? hintText;
final String? initialValue;
final void Function(String)? onChanged;
final ColorScheme? colorScheme;
@ -23,25 +23,42 @@ class HeaderField extends StatefulWidget {
}
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
Widget build(BuildContext context) {
var colorScheme = widget.colorScheme ?? Theme.of(context).colorScheme;
return TypeAheadFormField(
minCharsForSuggestions: 1,
hideOnEmpty: true,
return TypeAheadField(
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) {
return ListTile(
dense: true,
title: Text(suggestion),
);
},
suggestionsCallback: getHeaderSuggestions,
suggestionsCallback: headerSuggestionCallback,
suggestionsBoxDecoration: suggestionBoxDecorations(context),
textFieldConfiguration: TextFieldConfiguration(
onChanged: widget.onChanged!,
controller: widget.controller,
onChanged: (s) {
widget.onChanged?.call(s);
},
controller: controller,
style: kCodeStyle.copyWith(
color: colorScheme.onSurface,
),