Skip to content

AutoComplete OptionsViewOpenDirection.up positions does not work when custom optionsViewBuilder being passed #147483

@Vedsaga

Description

@Vedsaga

Steps to reproduce

  1. Copy & pasting the provided code
  2. Then running the app

Expected results

Even we use pass the custom options it should work normally.

Actual results

Custom options does not show up. While optionsViewBuilder does get invoked. Added the print statement confirms that.

If we comment the below code the Custom Options does seems works normally as it open down.

optionsViewOpenDirection: OptionsViewOpenDirection.up,

Code sample

import 'package:flutter/material.dart';

/// Flutter code sample for [Autocomplete].

void main() => runApp(const AutocompleteExampleApp());

class AutocompleteExampleApp extends StatelessWidget {
  const AutocompleteExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Autocomplete Basic'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                  'Type below to autocomplete the following possible results: ${AutocompleteBasicExample._kOptions}.'),
              const AutocompleteBasicExample(),
            ],
          ),
        ),
      ),
    );
  }
}

class AutocompleteBasicExample extends StatelessWidget {
  const AutocompleteBasicExample({super.key});

  static const List<String> _kOptions = <String>[
    'aardvark',
    'bobcat',
    'chameleon',
  ];

  @override
  Widget build(BuildContext context) {
    return Autocomplete<String>(
      optionsViewOpenDirection: OptionsViewOpenDirection.up,
      optionsBuilder: (TextEditingValue textEditingValue) {
        if (textEditingValue.text == '') {
          return const Iterable<String>.empty();
        }
        return _kOptions.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      onSelected: (String selection) {
        debugPrint('You just selected $selection');
      },
      optionsViewBuilder: (
        context,
        onSelected,
        options,
      ) {
        print(options.length);
        return CustomOptionsList(
          displayStringForOption: (prediction) {
            return prediction;
          },
        );
      },
    );
  }
}

class CustomOptionsList extends StatelessWidget {
  const CustomOptionsList({
    super.key,
    required this.displayStringForOption,
  });

  final String Function(String) displayStringForOption;

  @override
  Widget build(BuildContext context) {
    return Align(
        alignment: Alignment.topLeft,
        child: Material(
            elevation: 4,
            borderRadius: BorderRadius.circular(8),
            child: ConstrainedBox(
              constraints: const BoxConstraints(
                maxHeight: 200,
              ),
              child: ListView.builder(
                itemCount: AutocompleteBasicExample._kOptions.length,
                itemBuilder: (BuildContext context, int index) {
                  final String option =
                      AutocompleteBasicExample._kOptions[index];
                  return ListTile(
                    title: Text(displayStringForOption(option)),
                  );
                },
              ),
            )));
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[!] Flutter (Channel beta, 3.22.0-0.3.pre, on Microsoft Windows [Version 10.0.22631.3447], locale en-IN)
    • Flutter version 3.22.0-0.3.pre on channel beta at C:\Users\harsh\fvm\default
    ! Warning: `flutter` on your path resolves to C:\Users\harsh\fvm\versions\beta\bin\flutter, which is not inside your current Flutter SDK checkout at
      C:\Users\harsh\fvm\default. Consider adding C:\Users\harsh\fvm\default\bin to the front of your path.
    ! Warning: `dart` on your path resolves to C:\Users\harsh\fvm\versions\beta\bin\dart, which is not inside your current Flutter SDK checkout at
      C:\Users\harsh\fvm\default. Consider adding C:\Users\harsh\fvm\default\bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 87b652410d (4 days ago), 2024-04-23 21:41:18 -0500
    • Engine revision b4bfd45986
    • Dart version 3.4.0 (build 3.4.0-282.3.beta)
    • DevTools version 2.34.3
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\harsh\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[!] Android Studio (version 2022.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to determine bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[✓] IntelliJ IDEA Community Edition (version 2023.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2023.2.1
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.88.1)
    • VS Code at C:\Users\harsh\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.56.0

[✓] Connected device (1 available)
    • vivo 1907 (mobile) • 8TBYBE6H7H55USFE • android-arm64 • Android 12 (API 31)

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions