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

Issue: Input fields keep loosing focus #40

Closed
jasonlaw opened this issue Mar 26, 2019 · 12 comments
Closed

Issue: Input fields keep loosing focus #40

jasonlaw opened this issue Mar 26, 2019 · 12 comments

Comments

@jasonlaw
Copy link

Hi @danvick ,
After upgrading to version v2.0, my input fields keep loosing focus.

Below is not from my screen, but the problem is exactly the same.
1d8b82c2-a6dd-11e6-8f4c-31b772a500fd

Below is my code.
2019-03-26_081546

@jasonlaw
Copy link
Author

To add more info, I found that the form is always redraw when a input is getting focus.

These printed whenever I try to focus on the input textbox.
2019-03-26_084404

@jasonlaw
Copy link
Author

I have made a small changed in the code and it seems working, however, the behavior is still somewhat strange due to the formKey keep changing.

2019-03-26_092215

@danvick
Copy link
Collaborator

danvick commented Mar 26, 2019

Hey @jasonlaw,

Thanks for the help, you're the best.

Seems like I accidentally merged another branch which I was doing some experimental stuff on.

@danvick
Copy link
Collaborator

danvick commented Mar 26, 2019

@jasonlaw To avoid key changing, don't declare the global key inside your build method.

@jasonlaw
Copy link
Author

@danvick, thanks for the quick response. Indeed after moving out from the build method, it works normally now, you are awesome! :)

@benoitverstraete
Copy link

Hi,

I have the same behavior even if I move the global key in the class. I upgraded the package to the latest version (flutter_form_builder: ^2.0.3). It is impossible to enter a value in the fields.

Here is a sample of my code :

import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';

class ActivityPage extends StatelessWidget {
  final GlobalKey<FormBuilderState> _fbKey = GlobalKey();

  var data;

  final allCountries = [
    "Afghanistan",
    "Albania",
    "Algeria",
    "American Samoa",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('New activity'),
      ),
      body: SingleChildScrollView(
        child: FormBuilder(context, key: _fbKey, controls: [
          FormBuilderInput.typeAhead(
            decoration: InputDecoration(labelText: "Country"),
            attribute: 'country',
            // require: true,
            itemBuilder: (context, country) {
              return ListTile(
                title: Text(country),
              );
            },
            suggestionsCallback: (query) {
              if (query.length != 0) {
                var lowercaseQuery = query.toLowerCase();
                return allCountries.where((country) {
                  return country.toLowerCase().contains(lowercaseQuery);
                }).toList(growable: false)
                  ..sort((a, b) => a.toLowerCase().indexOf(lowercaseQuery).compareTo(b.toLowerCase().indexOf(lowercaseQuery)));
              } else {
                return allCountries;
              }
            },
          ),
          FormBuilderInput.textField(
            type: FormBuilderInput.TYPE_TEXT,
            attribute: "name",
            decoration: InputDecoration(labelText: "Full Name"),
            value: "John Doe",
          ),
        ]),
      ),
    );
  }
}

Could you please help me with this ?

Thanks a lot !

@danvick
Copy link
Collaborator

danvick commented Apr 4, 2019

Hi @benoitverstraete,
I've been unable to reproduce your error. Could you kindly share your version of flutter or the result of your flutter doctor

@danvick
Copy link
Collaborator

danvick commented Apr 4, 2019

You could also try converting your widget to a StatefulWidget especially if you want to make use of the data variable to get the result of your form

@benoitverstraete
Copy link

Yes, sure :

C:\src\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17763.379], locale en-GB)
    • Flutter version 1.2.1 at C:\src\flutter
    • Framework revision 8661d8aecd (7 weeks ago), 2019-02-14 19:19:53 -0800
    • Engine revision 3757390fa4
    • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\bve\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 34.0.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] VS Code (version 1.32.3)
    • VS Code at C:\Users\bve\AppData\Local\Programs\Microsoft VS Code
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (2 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
    • Android SDK built for x86 • emulator-5556 • android-x86 • Android 9 (API 28) (emulator)

! Doctor found issues in 1 category.

@benoitverstraete
Copy link

@danvick this bug disappear when I convert the StatelessWidget to a Stateful one, thanks !lba

But, I keep getting the error from the issue #33 for the typeAhead control...

@danvick
Copy link
Collaborator

danvick commented Apr 4, 2019

@benoitverstraete I'm quite sorry for the inconveniences. The package, as I later realized has quite a number of issues with state management. That's why I've taken to do complete rewrite coming out as version 3.0.0, in fact I've released a beta version of it just a few hours ago.

Feel free to test it out. I doubt if there will be major API changes before it's release

@benoitverstraete
Copy link

@danvick Ok, I will take a look at the new version and will open another issue if I encounter some issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants