Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FlutterFormBuilder]: using context.findAncestorStateOfType in FormBuilder.of #1474

Open
1 of 7 tasks
dadagov125 opened this issue Feb 26, 2025 · 0 comments
Open
1 of 7 tasks
Labels
bug Something isn't working

Comments

@dadagov125
Copy link

dadagov125 commented Feb 26, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.7.0

Platforms

  • Android
  • iOS
  • Linux
  • MacOS
  • Web
  • Windows

Flutter doctor

Flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 3.27.3, on macOS 15.2 24C101 darwin-arm64, locale ru-UZ)
    ✗ Downloaded executables cannot execute on host.
      See https://github.com/flutter/flutter/issues/6207 for more information.
      Flutter requires the Rosetta translation environment on ARM Macs. Try running:
        sudo softwareupdate --install-rosetta --agree-to-license

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    ✗ 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/to/macos-android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.3.2.2)
[✓] Connected device (5 available)            
    ! Error: Browsing on the local area network for iPhone 13 Magomed . 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)
[!] Network resources                                           
    ✗ A cryptographic error occurred while checking "https://pub.dev/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
    ✗ An HTTP error occurred while checking "https://storage.googleapis.com/": Connection closed before full header was received
    ✗ A cryptographic error occurred while checking "https://maven.google.com/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
    ✗ A network error occurred while checking "https://cocoapods.org/": Connection reset by peer
    ✗ A cryptographic error occurred while checking "https://github.com/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.

! Doctor found issues in 3 categories.

Minimal code example

Code sample
                    Builder(
                      builder: (context) {
                        final formState = FormBuilder.of(context);
                      },
                    );

Current Behavior

Currently, if you call FormBuilder.of in builder, it calls context.findAncestorStateOfType() which reduces the performance of the application because findAncestorStateOfType enumerates all parent nodes in the tree until it finds FormBuilderState.
In addition, with this approach, the current element is not updated when FormBuilderState changes.

Expected Behavior

FormBuilder.of must use context.dependOnInheritedWidgetOfExactType. Also InheritedWidget must be implemented for FormBuilderState.

  static FormBuilderState? of(BuildContext context, [bool listen = false]) {
    if (listen) {
      return context
          .dependOnInheritedWidgetOfExactType<_FormBuilderScope>()
          ._formState;
    }
    return context.findAncestorStateOfType<FormBuilderState>();
  }

Steps To Reproduce

  1. Create any widget.
  2. Wrap it in FormBuilder
  3. In the widget's build method, call FormBuilder.of(context)

Aditional information

No response

@dadagov125 dadagov125 added the bug Something isn't working label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant