flutter-form-builder-ecosystem / form_builder_extra_fields

Additional ready-made form input fields for flutter_form_builder package
https://pub.dev/packages/form_builder_extra_fields
BSD 3-Clause "New" or "Revised" License
28 stars 47 forks source link

[FormBuilderSearchableDropdown] how to open dropdown programatically #104

Open ronak-selldo opened 7 months ago

ronak-selldo commented 7 months ago

Is there an existing issue for this?

Package/Plugin version

8.3.0

Platforms

Flutter doctor

Flutter doctor ``` [✓] Flutter (Channel stable, 3.3.10, on macOS 13.5.2 22G91 darwin-arm, locale en-IN) • Flutter version 3.3.10 on channel stable at /Applications/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 135454af32 (1 year, 2 months ago), 2022-12-15 07:36:55 -0800 • Engine revision 3316dd8728 • Dart version 2.18.6 • DevTools version 2.15.0 [!] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/ronakkalavadia/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (version 2023.1) • Android Studio at /Applications/Android Studio.app/Contents • 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 find bundled Java version. • Try updating or re-installing Android Studio. [✓] Connected device (3 available) • iPhone 15 (mobile) • F0CD531E-982B-4CDC-B593-9E974CB747C1 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.5.2 22G91 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.139 ! Error: Browsing on the local area network for RK iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) ! Error: Browsing on the local area network for iPhone SE Old. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 2 categories. ```

Minimal code example

Code sample ```dart final _focusNode = FocusNode(); @override void initState() { afterBuild(() { _focusNode.requestFocus(); }); super.initState(); } return Column( mainAxisSize: MainAxisSize.min, children: [ ValueListenableBuilder( valueListenable: widget.field, builder: (context, dynamic value, _) { return FormBuilderSearchableDropdown( key: ValueKey(value), focusNode: _focusNode, name: widget.field.internalName!, items: const ["Brazil", "France", "Tunisia", "Canada"], compareFn: (String existingSelectedValue, String valueToBeRemoved) => existingSelectedValue == valueToBeRemoved, ); }), ], ); ```

Current Behavior

Dropdown is not opening with focusNode.

Expected Behavior

Dropdown should open with focus node.

Steps To Reproduce

  1. Set focus node of FormBuilderSearchableDropdown.
  2. Then set focusNode.requestFocus(); in init function.
  3. Dropdown not opening automatically.

Aditional information

No response

deandreamatias commented 7 months ago

Hi! This works using directly the package https://pub.dev/packages/dropdown_search? Also, add a minimal executable code example. Thanks

ronak-selldo commented 7 months ago

I think there is no focusNode available in this package.

DropdownSearch({ Key? key, this.onSaved, this.validator, this.autoValidateMode = AutovalidateMode.disabled, this.onChanged, this.items = const [], this.selectedItem, this.asyncItems, this.dropdownBuilder, this.dropdownDecoratorProps = const DropDownDecoratorProps(), this.clearButtonProps = const ClearButtonProps(), this.dropdownButtonProps = const DropdownButtonProps(), this.enabled = true, this.filterFn, this.itemAsString, this.compareFn, this.onBeforeChange, this.onBeforePopupOpening, PopupProps popupProps = const PopupProps.menu(), })

ronak-selldo commented 7 months ago

Minimal code sample.

final _focusNode = FocusNode();

@override
  void initState() {
    afterBuild(() {
          _focusNode.requestFocus();
    });
    super.initState();
  }

return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        ValueListenableBuilder(
            valueListenable: widget.field,
            builder: (context, dynamic value, _) {
              return FormBuilderSearchableDropdown<String>(
                key: ValueKey(value),
                focusNode: _focusNode,
                name: widget.field.internalName!,
                items: const ["Brazil", "France", "Tunisia", "Canada"],
                compareFn:
                    (String existingSelectedValue, String valueToBeRemoved) =>
                        existingSelectedValue == valueToBeRemoved,
              );
            }),
      ],
    );