-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Keyboard or focusNode #22
Comments
You can retrieve the context of the last builder widget using Get.key.currentWidget from anywhere in your code. onSubmitted: (_) => FocusScope.of(Get.key.currentContext).nextFocus(), // move focus to next |
Sorry but this is not working at all: next Focus never call when I use with Get.key.currentContext Also when I use this:
then the probleme is: First time it is working like a charm, But after I write something in the field and submit called setState or changeNotifier, the second time when click in the TextField my keyboard just pop up and immediatelly pop down (show and hide) and lose focus Also I have to generate on the fly a lot of TextField and controllers for that and perhaps listeners to that... Can you help me how to fix this? Basically what I want: Row1 [Textfield][Textfield][Textfield] ADD -> Row1 [Textfield][Textfield][Textfield] DEL -> Row1 [Textfield][Textfield][Textfield] Also I have to save those values in somehow and refresh the UI, via setState or changeNotifier I also find this BUG in the flutter app: |
Here is my textfield code
and my listeners generating in realtime after build something like this:
|
You are probably swapping some StatefulWidget for StatelessWidget, or inserting controllers inside build methods instead of inserting them at the beginning of a Stateful class. |
So basically I have to create all the TextEditingControllers in initState instead of build? That will work? |
Just like I told you in that comment: Controllers can NEVER be inside builders, no matter if it’s the main build (context) widget, or inside a StreamBuilder, FutureBuilder, BottomSheet, because at each setState a new controller will be created. You can never do this: class Example extends StatelessWidget {
const Example({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final _editText = TextEditingController(); // NEVER DO THAT. Controllers should never be within builder methods.
return TextField(
controller: _editText,
);
}
}
You should ALWAYS do this: class Example extends StatefulWidget {
// If you have any controller it is mandatory to use StatefulWidget.
Example({Key key}) : super(key: key);
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
final TextEditingController _editText = TextEditingController(); // HERE
@override
Widget build(BuildContext context) {
return TextField(
controller: _editText,
);
}
}
You can also create the controller in the mentioned place, and instantiate it in your initState, so it will only be called once, however, for code security reasons, I recommend doing it as above. Note that this is not related to this library, and as much as I want to help you, it can mess up people who are looking for something in issues. Reserve this field only for issues directly related to Get. |
Is there any way to use nextFocus without a context? Because when my TextField in a widget that is opened via Get my keyboard is going to be crazy from this line:
onSubmitted: (_) => FocusScope.of(context).nextFocus(), // move focus to next
),
The text was updated successfully, but these errors were encountered: