1
+ import 'package:apidash/consts.dart' ;
1
2
import 'package:apidash/utils/header_utils.dart' ;
2
3
import 'package:flutter/material.dart' ;
3
- import 'package:apidash/consts.dart' ;
4
4
import 'package:flutter_typeahead/flutter_typeahead.dart' ;
5
5
6
6
class HeaderField extends StatefulWidget {
@@ -41,6 +41,7 @@ class _HeaderFieldState extends State<HeaderField> {
41
41
42
42
@override
43
43
void didUpdateWidget (HeaderField oldWidget) {
44
+ super .didUpdateWidget (oldWidget);
44
45
if (oldWidget.initialValue != widget.initialValue) {
45
46
controller.text = widget.initialValue ?? "" ;
46
47
controller.selection =
@@ -54,8 +55,8 @@ class _HeaderFieldState extends State<HeaderField> {
54
55
return TypeAheadField (
55
56
key: Key (widget.keyId),
56
57
hideOnEmpty: true ,
57
- minCharsForSuggestions : 1 ,
58
- onSuggestionSelected : (value) {
58
+ controller : controller ,
59
+ onSelected : (value) {
59
60
setState (() {
60
61
controller.text = value;
61
62
});
@@ -68,19 +69,17 @@ class _HeaderFieldState extends State<HeaderField> {
68
69
);
69
70
},
70
71
suggestionsCallback: headerSuggestionCallback,
71
- suggestionsBoxDecoration: suggestionBoxDecorations (context),
72
- textFieldConfiguration: TextFieldConfiguration (
72
+ decorationBuilder: (context, child) =>
73
+ suggestionBoxDecorations (context, child, colorScheme),
74
+ constraints: const BoxConstraints (maxHeight: 400 ),
75
+ builder: (context, controller, focusNode) => TextField (
73
76
onChanged: widget.onChanged,
74
77
controller: controller,
75
- style: kCodeStyle.copyWith (
76
- color: colorScheme.onSurface,
77
- ),
78
+ focusNode: focusNode,
79
+ style: kCodeStyle.copyWith (color: colorScheme.onSurface),
78
80
decoration: InputDecoration (
79
81
hintStyle: kCodeStyle.copyWith (
80
- color: colorScheme.outline.withOpacity (
81
- kHintOpacity,
82
- ),
83
- ),
82
+ color: colorScheme.outline.withOpacity (kHintOpacity)),
84
83
hintText: widget.hintText,
85
84
focusedBorder: UnderlineInputBorder (
86
85
borderSide: BorderSide (
@@ -99,22 +98,26 @@ class _HeaderFieldState extends State<HeaderField> {
99
98
);
100
99
}
101
100
102
- SuggestionsBoxDecoration suggestionBoxDecorations (BuildContext context) {
103
- return SuggestionsBoxDecoration (
104
- elevation: 4 ,
105
- constraints: const BoxConstraints (maxHeight: 400 ),
106
- shape: RoundedRectangleBorder (
107
- side: BorderSide (
108
- color: Theme .of (context).dividerColor,
109
- width: 1.2 ,
101
+ Theme suggestionBoxDecorations (
102
+ BuildContext context, Widget child, ColorScheme colorScheme) {
103
+ return Theme (
104
+ data: ThemeData (colorScheme: colorScheme),
105
+ child: Material (
106
+ elevation: 4 ,
107
+ shape: RoundedRectangleBorder (
108
+ side: BorderSide (color: Theme .of (context).dividerColor, width: 1.2 ),
109
+ borderRadius: const BorderRadius .vertical (bottom: Radius .circular (8 )),
110
110
),
111
- borderRadius: const BorderRadius .vertical (bottom: Radius .circular (8 )),
111
+ clipBehavior: Clip .hardEdge,
112
+ child: child,
112
113
),
113
- clipBehavior: Clip .hardEdge,
114
114
);
115
115
}
116
116
117
- Future <List <String >> headerSuggestionCallback (String pattern) async {
117
+ Future <List <String >?> headerSuggestionCallback (String pattern) async {
118
+ if (pattern.isEmpty) {
119
+ return null ;
120
+ }
118
121
return getHeaderSuggestions (pattern);
119
122
}
120
123
}
0 commit comments