Skip to content

Commit

Permalink
Merge pull request #199 from OUFA217/master
Browse files Browse the repository at this point in the history
Add Optional Scroll Controller
  • Loading branch information
maheshj01 authored Dec 24, 2024
2 parents 8fb65bc + d92bb1b commit d276ec4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Form(
hint: 'SearchField Example 2',
searchStyle: TextStyle(
fontSize: 18,
color: Colors.black.withOpacity(0.8),
color: Colors.black.withValues(alpha: 0.8),
),
validator: (x) {
if (!_statesOfIndia.contains(x) || x!.isEmpty) {
Expand All @@ -184,7 +184,7 @@ Form(
searchInputDecoration: SearchInputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black.withOpacity(0.8),
color: Colors.black.withValues(alpha: 0.8),
),
),
border: OutlineInputBorder(
Expand Down
13 changes: 9 additions & 4 deletions lib/src/searchfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class SearchField<T> extends StatefulWidget {
/// This callback returns the text from the searchfield
final Function(String)? onSubmit;

/// Scroll Controller for the suggestion list
final ScrollController? scrollController;

/// Hint for the [SearchField].
final String? hint;

Expand Down Expand Up @@ -183,7 +186,7 @@ class SearchField<T> extends StatefulWidget {
/// color: Theme.of(context).colorScheme.surface,
/// boxShadow: [
/// BoxShadow(
/// color: onSurfaceColor.withOpacity(0.1),
/// color: onSurfaceColor.withValues(alpha: 0.1),
/// blurRadius: 8.0, // soften the shadow
/// spreadRadius: 2.0, //extend the shadow
/// offset: Offset(
Expand All @@ -206,7 +209,7 @@ class SearchField<T> extends StatefulWidget {
/// border: Border(
/// bottom: BorderSide(
/// color: widget.marginColor ??
/// onSurfaceColor.withOpacity(0.1),
/// onSurfaceColor.withValues(alpha: 0.1),
/// ),
/// ),
/// )
Expand Down Expand Up @@ -234,7 +237,7 @@ class SearchField<T> extends StatefulWidget {

/// Specifies the color of margin between items in suggestions list.
///
/// When not specified, the default value is `Theme.of(context).colorScheme.onSurface.withOpacity(0.1)`.
/// When not specified, the default value is `Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.1)`.
final Color? marginColor;

/// Specifies the number of suggestions that can be shown in viewport.
Expand Down Expand Up @@ -339,6 +342,7 @@ class SearchField<T> extends StatefulWidget {
required this.suggestions,
this.animationDuration = const Duration(milliseconds: 300),
this.autoCorrect = true,
this.scrollController,
this.autofocus = false,
this.autovalidateMode,
this.contextMenuBuilder,
Expand Down Expand Up @@ -421,6 +425,7 @@ class _SearchFieldState<T> extends State<SearchField<T>> {
if (widget.focusNode == null) {
_searchFocus!.dispose();
}

removeOverlay();
super.dispose();
}
Expand Down Expand Up @@ -536,7 +541,7 @@ class _SearchFieldState<T> extends State<SearchField<T>> {
});
_unFocusAction =
KCallbackAction<UnFocusIntent>(onInvoke: handleUnFocusKeyPress);
_scrollController = ScrollController();
_scrollController = widget.scrollController ?? ScrollController();
searchController = widget.controller ?? TextEditingController();
_suggestionDirection = widget.suggestionDirection;
filteredResult.addAll(widget.suggestions);
Expand Down

0 comments on commit d276ec4

Please sign in to comment.