Rename AutocompleteCore to RawAutocomplete to match similar naming elsewhere in Flutter (#69419)
We are standardizing around the term Raw for lower level widgets.
This commit is contained in:
committed by
GitHub
parent
c4ceea397a
commit
22f3cd8a67
@@ -12,27 +12,27 @@ import 'focus_manager.dart';
|
||||
import 'framework.dart';
|
||||
import 'overlay.dart';
|
||||
|
||||
/// The type of the [AutocompleteCore] callback which computes the list of
|
||||
/// The type of the [RawAutocomplete] callback which computes the list of
|
||||
/// optional completions for the widget's field based on the text the user has
|
||||
/// entered so far.
|
||||
///
|
||||
/// See also:
|
||||
/// * [AutocompleteCore.optionsBuilder], which is of this type.
|
||||
/// * [RawAutocomplete.optionsBuilder], which is of this type.
|
||||
typedef AutocompleteOptionsBuilder<T extends Object> = Iterable<T> Function(TextEditingValue textEditingValue);
|
||||
|
||||
/// The type of the callback used by the [AutocompleteCore] widget to indicate
|
||||
/// The type of the callback used by the [RawAutocomplete] widget to indicate
|
||||
/// that the user has selected an option.
|
||||
///
|
||||
/// See also:
|
||||
/// * [AutocompleteCore.onSelected], which is of this type.
|
||||
/// * [RawAutocomplete.onSelected], which is of this type.
|
||||
typedef AutocompleteOnSelected<T extends Object> = void Function(T option);
|
||||
|
||||
/// The type of the [AutocompleteCore] callback which returns a [Widget] that
|
||||
/// The type of the [RawAutocomplete] callback which returns a [Widget] that
|
||||
/// displays the specified [options] and calls [onSelected] if the user
|
||||
/// selects an option.
|
||||
///
|
||||
/// See also:
|
||||
/// * [AutocompleteCore.optionsViewBuilder], which is of this type.
|
||||
/// * [RawAutocomplete.optionsViewBuilder], which is of this type.
|
||||
typedef AutocompleteOptionsViewBuilder<T extends Object> = Widget Function(
|
||||
BuildContext context,
|
||||
AutocompleteOnSelected<T> onSelected,
|
||||
@@ -43,7 +43,7 @@ typedef AutocompleteOptionsViewBuilder<T extends Object> = Widget Function(
|
||||
/// contains the input [TextField] or [TextFormField].
|
||||
///
|
||||
/// See also:
|
||||
/// * [AutocompleteCore.fieldViewBuilder], which is of this type.
|
||||
/// * [RawAutocomplete.fieldViewBuilder], which is of this type.
|
||||
typedef AutocompleteFieldViewBuilder = Widget Function(
|
||||
BuildContext context,
|
||||
TextEditingController textEditingController,
|
||||
@@ -51,11 +51,11 @@ typedef AutocompleteFieldViewBuilder = Widget Function(
|
||||
VoidCallback onFieldSubmitted,
|
||||
);
|
||||
|
||||
/// The type of the [AutocompleteCore] callback that converts an option value to
|
||||
/// The type of the [RawAutocomplete] callback that converts an option value to
|
||||
/// a string which can be displayed in the widget's options menu.
|
||||
///
|
||||
/// See also:
|
||||
/// * [AutocompleteCore.displayStringForOption], which is of this type.
|
||||
/// * [RawAutocomplete.displayStringForOption], which is of this type.
|
||||
typedef AutocompleteOptionToString<T extends Object> = String Function(T option);
|
||||
|
||||
// TODO(justinmc): Mention Autocomplete and AutocompleteCupertino when they are
|
||||
@@ -90,7 +90,7 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
///
|
||||
/// @override
|
||||
/// Widget build(BuildContext context) {
|
||||
/// return AutocompleteCore<String>(
|
||||
/// return RawAutocomplete<String>(
|
||||
/// optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
/// return _options.where((String option) {
|
||||
/// return option.contains(textEditingValue.text.toLowerCase());
|
||||
@@ -194,7 +194,7 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
///
|
||||
/// @override
|
||||
/// Widget build(BuildContext context) {
|
||||
/// return AutocompleteCore<User>(
|
||||
/// return RawAutocomplete<User>(
|
||||
/// optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
/// return _userOptions.where((User option) {
|
||||
/// // Search based on User.toString, which includes both name and
|
||||
@@ -245,7 +245,7 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// {@tool dartpad --template=freeform}
|
||||
/// This example shows the use of AutocompleteCore in a form.
|
||||
/// This example shows the use of RawAutocomplete in a form.
|
||||
///
|
||||
/// ```dart imports
|
||||
/// import 'package:flutter/widgets.dart';
|
||||
@@ -321,7 +321,7 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
/// return null;
|
||||
/// },
|
||||
/// ),
|
||||
/// AutocompleteCore<String>(
|
||||
/// RawAutocomplete<String>(
|
||||
/// optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
/// return _options.where((String option) {
|
||||
/// return option.contains(textEditingValue.text.toLowerCase());
|
||||
@@ -336,7 +336,7 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
/// return TextFormField(
|
||||
/// controller: textEditingController,
|
||||
/// decoration: InputDecoration(
|
||||
/// hintText: 'This is an AutocompleteCore!',
|
||||
/// hintText: 'This is an RawAutocomplete!',
|
||||
/// ),
|
||||
/// focusNode: focusNode,
|
||||
/// onFieldSubmitted: (String value) {
|
||||
@@ -393,7 +393,7 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
/// children: <Widget>[
|
||||
/// Text('DropdownButtonFormField: "$_dropdownValue"'),
|
||||
/// Text('TextFormField: "${_textEditingController.text}"'),
|
||||
/// Text('AutocompleteCore: "$_autocompleteSelection"'),
|
||||
/// Text('RawAutocomplete: "$_autocompleteSelection"'),
|
||||
/// ],
|
||||
/// ),
|
||||
/// ),
|
||||
@@ -420,11 +420,11 @@ typedef AutocompleteOptionToString<T extends Object> = String Function(T option)
|
||||
/// }
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
class AutocompleteCore<T extends Object> extends StatefulWidget {
|
||||
/// Create an instance of AutocompleteCore.
|
||||
class RawAutocomplete<T extends Object> extends StatefulWidget {
|
||||
/// Create an instance of RawAutocomplete.
|
||||
///
|
||||
/// [fieldViewBuilder] and [optionsViewBuilder] must not be null.
|
||||
const AutocompleteCore({
|
||||
const RawAutocomplete({
|
||||
Key? key,
|
||||
required this.fieldViewBuilder,
|
||||
required this.optionsViewBuilder,
|
||||
@@ -440,14 +440,14 @@ class AutocompleteCore<T extends Object> extends StatefulWidget {
|
||||
/// Builds the field whose input is used to get the options.
|
||||
///
|
||||
/// Pass the provided [TextEditingController] to the field built here so that
|
||||
/// AutocompleteCore can listen for changes.
|
||||
/// RawAutocomplete can listen for changes.
|
||||
final AutocompleteFieldViewBuilder fieldViewBuilder;
|
||||
|
||||
/// Builds the selectable options widgets from a list of options objects.
|
||||
///
|
||||
/// The options are displayed floating below the field using a
|
||||
/// [CompositedTransformFollower] inside of an [Overlay], not at the same
|
||||
/// place in the widget tree as AutocompleteCore.
|
||||
/// place in the widget tree as RawAutocomplete.
|
||||
final AutocompleteOptionsViewBuilder<T> optionsViewBuilder;
|
||||
|
||||
/// Returns the string to display in the field when the option is selected.
|
||||
@@ -475,10 +475,10 @@ class AutocompleteCore<T extends Object> extends StatefulWidget {
|
||||
}
|
||||
|
||||
@override
|
||||
_AutocompleteCoreState<T> createState() => _AutocompleteCoreState<T>();
|
||||
_RawAutocompleteState<T> createState() => _RawAutocompleteState<T>();
|
||||
}
|
||||
|
||||
class _AutocompleteCoreState<T extends Object> extends State<AutocompleteCore<T>> {
|
||||
class _RawAutocompleteState<T extends Object> extends State<RawAutocomplete<T>> {
|
||||
final GlobalKey _fieldKey = GlobalKey();
|
||||
final LayerLink _optionsLayerLink = LayerLink();
|
||||
final TextEditingController _textEditingController = TextEditingController();
|
||||
@@ -566,7 +566,7 @@ class _AutocompleteCoreState<T extends Object> extends State<AutocompleteCore<T>
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AutocompleteCore<T> oldWidget) {
|
||||
void didUpdateWidget(RawAutocomplete<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
SchedulerBinding.instance!.addPostFrameCallback((Duration _) {
|
||||
_updateOverlay();
|
||||
|
||||
@@ -45,7 +45,7 @@ void main() {
|
||||
User(name: 'Charlie', email: 'charlie123@gmail.com'),
|
||||
];
|
||||
|
||||
group('AutocompleteCore', () {
|
||||
group('RawAutocomplete', () {
|
||||
testWidgets('can filter and select a list of string options', (WidgetTester tester) async {
|
||||
final GlobalKey fieldKey = GlobalKey();
|
||||
final GlobalKey optionsKey = GlobalKey();
|
||||
@@ -57,7 +57,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: AutocompleteCore<String>(
|
||||
body: RawAutocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
return kOptions.where((String option) {
|
||||
return option.contains(textEditingValue.text.toLowerCase());
|
||||
@@ -142,7 +142,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: AutocompleteCore<User>(
|
||||
body: RawAutocomplete<User>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
return kOptionsUsers.where((User option) {
|
||||
return option.toString().contains(textEditingValue.text.toLowerCase());
|
||||
@@ -221,7 +221,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: AutocompleteCore<User>(
|
||||
body: RawAutocomplete<User>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
return kOptionsUsers.where((User option) {
|
||||
return option
|
||||
@@ -302,7 +302,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: AutocompleteCore<String>(
|
||||
body: RawAutocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
return kOptions.where((String option) {
|
||||
return option.contains(textEditingValue.text.toLowerCase());
|
||||
@@ -365,7 +365,7 @@ void main() {
|
||||
setState = setter;
|
||||
return Align(
|
||||
alignment: alignment,
|
||||
child: AutocompleteCore<String>(
|
||||
child: RawAutocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
return kOptions.where((String option) {
|
||||
return option.contains(textEditingValue.text.toLowerCase());
|
||||
@@ -433,7 +433,7 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: AutocompleteCore<String>(
|
||||
body: RawAutocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
if (textEditingValue.text == null || textEditingValue.text == '') {
|
||||
return const Iterable<String>.empty();
|
||||
|
||||
Reference in New Issue
Block a user