Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Dec 13, 2024
2 parents 1cfd00f + db6ece5 commit 2c2adc7
Show file tree
Hide file tree
Showing 17 changed files with 459 additions and 427 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/no-response.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
issue_comment:
types: [created]
schedule:
- cron: '30 * * * *'
- cron: '0 1 * * *'

permissions:
issues: write
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
- Highlighted suggestion in controller

## 5.2.0 - 2024-02-08
### Added
- force refreshing suggestions with `SuggestionsController.refresh`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ Additionally, various changes have been made to the API surface to make the pack
- `intercepting`: This is now always true, since it doesnt interfere on mobile platforms and generally has no downsides.
- `onSuggestionsBoxToggle`: You can subscribe to the `SuggestionsController` to get notified when the suggestions box is toggled.
- `ignoreAccessibleNavigation`: The new `Overlay` code no longer requires to act differently when accessibility is enabled.
- `minCharsForSuggestions`: You can return an empty list from `suggestionsCallback` instead.
- `minCharsForSuggestions`: You can return `null` from `suggestionsCallback` instead.
- `animationStart`: You can use the animation in the builder and map it to customise this.
- `autoFlipListDirection`: This is now always true. You can use the list builder to disable this behavior.
- `getImmediateSuggestions`: You can use the `debounceDuration` to achieve the same effect.
Expand Down
5 changes: 3 additions & 2 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ app.*.map.json
/android/app/release


# Platform folders
# Platform dependent files
/web/
/windows/
/macos/
/linux/
/android/
/ios/
/ios/
.metadata
30 changes: 0 additions & 30 deletions example/.metadata

This file was deleted.

51 changes: 51 additions & 0 deletions lib/src/common/base/suggestions_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -52,6 +53,56 @@ class SuggestionsController<T> extends ChangeNotifier {

List<T>? _suggestions;

/// The index of the highlighted suggestion in the suggestions box.
int? get highlighted => _highlighted;
set highlighted(int? value) {
if (_highlighted == value) return;
_highlighted = value;
notifyListeners();
}

int? _highlighted;

/// Removes the highlight from the suggestions box.
void unhighlight() => highlighted = null;

/// Highlights the previous suggestion in the suggestions box.
void highlightPrevious() {
if (highlighted == null) return;
if (highlighted! <= 0) {
highlighted = null;
} else {
int max = suggestions == null ? 0 : suggestions!.length - 1;
highlighted = min(highlighted! - 1, max);
}
}

/// Highlights the next suggestion in the suggestions box.
void highlightNext() {
if (highlighted == null) {
highlighted = 0;
} else {
int max = suggestions == null ? 0 : suggestions!.length - 1;
highlighted = min(highlighted! + 1, max);
}
}

/// The highlighted suggestion in the suggestions box.
///
/// This is the suggestion at the index of [highlighted].
T? get highlightedSuggestion {
if (highlighted == null) return null;
return suggestions?.elementAtOrNull(highlighted!);
}

set highlightedSuggestion(T? value) {
if (value == null) {
highlighted = null;
} else {
highlighted = suggestions?.indexOf(value);
}
}

/// A stream of events that occur when the suggestions list should be refreshed.
///
/// For internal use only.
Expand Down
22 changes: 9 additions & 13 deletions lib/src/common/box/suggestions_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter_typeahead/src/common/base/types.dart';
import 'package:flutter_typeahead/src/common/box/suggestions_box_animation.dart';
import 'package:flutter_typeahead/src/common/box/suggestions_box_focus_connector.dart';
import 'package:flutter_typeahead/src/common/box/suggestions_box_scroll_injector.dart';
import 'package:flutter_typeahead/src/common/box/suggestions_box_traversal_connector.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';

/// A widget that contains suggestions based on user input.
Expand Down Expand Up @@ -110,18 +109,15 @@ class SuggestionsBox<T> extends StatelessWidget {
controller: scrollController,
child: SuggestionsBoxFocusConnector<T>(
controller: controller,
child: SuggestionsBoxTraversalConnector<T>(
controller: controller,
child: PointerInterceptor(
child: Builder(
builder: (context) => wrapper(
context,
SuggestionsBoxAnimation<T>(
controller: controller,
transitionBuilder: transitionBuilder,
animationDuration: animationDuration,
child: builder(context),
),
child: PointerInterceptor(
child: Builder(
builder: (context) => wrapper(
context,
SuggestionsBoxAnimation<T>(
controller: controller,
transitionBuilder: transitionBuilder,
animationDuration: animationDuration,
child: builder(context),
),
),
),
Expand Down
82 changes: 0 additions & 82 deletions lib/src/common/box/suggestions_box_traversal_connector.dart

This file was deleted.

5 changes: 2 additions & 3 deletions lib/src/common/field/suggestions_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'package:flutter_typeahead/src/common/box/suggestions_box.dart';
import 'package:flutter_typeahead/src/common/base/suggestions_controller.dart';
import 'package:flutter_typeahead/src/common/base/types.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_focus_connector.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_highlight_connector.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_keyboard_connector.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_box_connector.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_select_connector.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_tap_connector.dart';
import 'package:flutter_typeahead/src/common/field/suggestions_field_traversal_connector.dart';

/// A widget that displays a list of suggestions above or below another widget.
class SuggestionsField<T> extends StatefulWidget {
Expand Down Expand Up @@ -278,9 +278,8 @@ class _SuggestionsFieldState<T> extends State<SuggestionsField<T>> {
child: SuggestionsFieldFocusConnector<T>(
controller: controller,
focusNode: widget.focusNode,
child: SuggestionsFieldTraversalConnector<T>(
child: SuggestionsFieldHighlightConnector<T>(
controller: controller,
focusNode: widget.focusNode,
child: SuggestionsFieldBoxConnector<T>(
controller: controller,
showOnFocus: widget.showOnFocus,
Expand Down
Loading

0 comments on commit 2c2adc7

Please sign in to comment.