improve search box
This commit is contained in:
+4
-1
@@ -127,13 +127,16 @@ class SearchField extends HookConsumerWidget {
|
||||
controller: textEditingController,
|
||||
suggestion: suggestion.value,
|
||||
acceptSuggestionOnSubmit: acceptSuggestionOnSubmit,
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
enableIMEPersonalizedLearning: !incognitoEnabled,
|
||||
focusNode: safeFocusNode,
|
||||
maxLines: maxLines,
|
||||
textFieldKey: textFieldKey,
|
||||
keyboardType: TextInputType.webSearch,
|
||||
textInputAction: (maxLines == null || maxLines! > 1)
|
||||
? TextInputAction.done
|
||||
: TextInputAction.search,
|
||||
: TextInputAction.send,
|
||||
minLines: minLines,
|
||||
autofocus: autofocus,
|
||||
onSuggestionDismiss: () {
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class WebSearchField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final bool enabled;
|
||||
final Future<void> Function(String query) onSubmitted;
|
||||
final VoidCallback onClear;
|
||||
|
||||
const WebSearchField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.enabled,
|
||||
required this.onSubmitted,
|
||||
required this.onClear,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
height: 60,
|
||||
padding: const EdgeInsets.only(left: 20, right: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
border: Border.all(color: colorScheme.outlineVariant),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.search, color: colorScheme.onSurfaceVariant),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
enabled: enabled,
|
||||
minLines: 1,
|
||||
maxLines: 5,
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: TextInputAction.search,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyLarge?.copyWith(color: colorScheme.onSurface),
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintText: 'Search the web...',
|
||||
hintStyle: TextStyle(color: colorScheme.onSurfaceVariant),
|
||||
isDense: true,
|
||||
),
|
||||
onSubmitted: enabled ? onSubmitted : null,
|
||||
),
|
||||
),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, child) {
|
||||
if (value.text.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
tooltip: 'Clear',
|
||||
onPressed: enabled ? onClear : null,
|
||||
icon: Icon(Icons.close, color: colorScheme.onSurfaceVariant),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
FilledButton(
|
||||
onPressed: enabled ? () => onSubmitted(controller.text) : null,
|
||||
style: FilledButton.styleFrom(
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
),
|
||||
child: const Text('Search'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class AutoSuggestTextField extends HookWidget {
|
||||
final TapRegionCallback? onTapOutside;
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onSuggestionDismiss;
|
||||
final bool enableSuggestions;
|
||||
final bool autocorrect;
|
||||
final GlobalKey? textFieldKey;
|
||||
|
||||
@@ -86,6 +87,7 @@ class AutoSuggestTextField extends HookWidget {
|
||||
this.onTapOutside,
|
||||
this.onTap,
|
||||
this.onSuggestionDismiss,
|
||||
this.enableSuggestions = false,
|
||||
this.autocorrect = false,
|
||||
this.textFieldKey,
|
||||
this.acceptSuggestionOnSubmit = false,
|
||||
@@ -217,6 +219,7 @@ class AutoSuggestTextField extends HookWidget {
|
||||
onChanged: onChanged,
|
||||
onEditingComplete: onEditingComplete,
|
||||
validator: validator,
|
||||
enableSuggestions: enableSuggestions,
|
||||
autocorrect: autocorrect,
|
||||
onFieldSubmitted: onSubmitted.mapNotNull(
|
||||
(onSubmitted) => (value) {
|
||||
|
||||
Reference in New Issue
Block a user