Unverified Commit 22f3cd8a authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Rename AutocompleteCore to RawAutocomplete to match similar naming elsewhere in Flutter (#69419)

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