keyboard_search_dialog 1.0.0+1
keyboard_search_dialog: ^1.0.0+1 copied to clipboard
A Flutter package that provides a keyboard-controlled autocomplete widget with a search dialog. Perfect for creating searchable dropdowns and autocomplete fields that open a search dialog on keyboard input.
keyboard_search_dialog #
A Flutter package that provides a keyboard-controlled autocomplete widget with a search dialog. Perfect for creating searchable dropdowns and autocomplete fields that open a search dialog on keyboard input.
Features #
- Keyboard Controlled: Automatically opens search dialog on Enter key or printable character input
- Customizable Search Dialog: Fully customizable search dialog with filtering capabilities
- Focus Management: Built-in focus handling with support for next focus nodes
- Flexible Styling: Customizable appearance for both input field and search dialog
- Type Safe: Generic implementation supporting any data type
- Accessibility: Built with accessibility in mind
Getting Started #
Add this to your package's pubspec.yaml file:
dependencies:
keyboard_search_dialog: ^1.0.0
Usage #
Basic Usage #
import 'package:keyboard_search_dialog/keyboard_search_dialog.dart';
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
final TextEditingController _controller = TextEditingController();
final FocusNode _focusNode = FocusNode();
@override
Widget build(BuildContext context) {
return KeyboardControlledAutocomplete<String>(
options: const ['Apple', 'Banana', 'Cherry', 'Date'],
displayStringForOption: (item) => item,
onSelected: (value) {
print('Selected: $value');
},
controller: _controller,
focusNode: _focusNode,
label: 'Select a fruit',
);
}
@override
void dispose() {
_controller.dispose();
_focusNode.dispose();
super.dispose();
}
}
Advanced Usage with Custom Styling #
KeyboardControlledAutocomplete<String>(
options: const ['Red', 'Green', 'Blue', 'Yellow'],
displayStringForOption: (color) => color,
onSelected: (color) {
setState(() {
selectedColor = color;
});
},
controller: _controller,
focusNode: _focusNode,
// Input field styling
label: 'Choose a color',
labelStyle: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
textStyle: TextStyle(fontSize: 18),
focusColor: Colors.blue,
// Search dialog styling
backgroundColor: Colors.white,
highlightedTileColor: Colors.blue.shade50,
maxWidth: 400,
height: 500,
// Custom search field decoration
searchFieldDecoration: InputDecoration(
hintText: 'Search colors...',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.search),
),
// Custom option builder
optionBuilder: (context, color, isHighlighted) {
return ListTile(
title: Text(color),
tileColor: isHighlighted ? Colors.blue.shade100 : null,
leading: Icon(Icons.circle, color: _getColorValue(color)),
);
},
);
API Reference #
KeyboardControlledAutocomplete #
The main widget that provides keyboard-controlled autocomplete functionality.
Required Parameters
options: The list of available optionsdisplayStringForOption: Function to convert option to display stringonSelected: Callback when an option is selectedcontroller: TextEditingController for the input fieldfocusNode: FocusNode for the input field
Optional Parameters
Input Field Styling
label: Label text for the input fieldlabelStyle: TextStyle for the labelhintStyle: TextStyle for the hint texttextStyle: TextStyle for the input textvalidator: Form validation functioncontentPadding: Padding for the input fieldcanFillColor: Whether to fill the input field with colorfocusColor: Color when the field is focused
Focus Management
nextFocusNode: FocusNode to focus after selectionnextFocus: Alternative focus nodefallbackFocusOnCancel: Focus node when dialog is cancelled
Search Dialog Styling
height: Height of the search dialogbackgroundColor: Background color of the dialoghighlightedTileColor: Color for highlighted optionsdialogTextFieldStyle: TextStyle for dialog search fieldsearchFieldDecoration: InputDecoration for dialog search fieldcloseButtonIcon: Icon for the close buttoncloseButtonColor: Color for the close buttondialogShape: Shape border for the dialogmaxWidth: Maximum width of the dialogmaxHeightFactor: Maximum height factor relative to screenoptionItemHeight: Height of each option item
Content Customization
noResultsText: Text to show when no results foundnoResultsTextStyle: TextStyle for no results textnoResultsBuilder: Custom builder for no results stateoptionBuilder: Custom builder for option itemsbarrierDismissible: Whether dialog can be dismissed by tapping outsidebarrierColor: Color of the barrier behind the dialogautoFocusSearchField: Whether to auto-focus the search field in dialog
Example #
Check out the example app in the example/ directory to see the widget in action.
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.