OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.88k stars 496 forks source link

Keyboard is closed immediately when trying to write inside dialog #494

Closed Khawlah-Mohammed closed 1 year ago

Khawlah-Mohammed commented 1 year ago

I have some TextFormField inside dialog .. while trying to write on them the keyboard is shown and closed immediately.

Khawlah-Mohammed commented 1 year ago

Sorry, it is an issue with something els.

842787863 commented 1 year ago

Sorry, it is an issue with something els.

Can you tell me what went wrong? I had the same problem, you know? thank you

Heilum commented 1 year ago

@842787863 ,just define your FormKey/TextEditingController outside, not inside the closure!

Khawlah-Mohammed commented 1 year ago

Thanks, I have done that and it solved the problem.

842787863 commented 1 year ago

@Heilum Thanks! I solved this problem after replacing MediaQuery with LayoutBuilder, TextEditing is not refreshing other widgets

janek515 commented 1 year ago

@842787863 ,just define your FormKey/TextEditingController outside, not inside the closure!

Hi! Could you give me a small example of what you're trying to explain? I'm trying to tackle the same problem and don't know what to do. Also, I'm using TextEditingController through flutter_hooks.

Thanks in advance!

842787863 commented 1 year ago

@janek515 Hi, flutter_screenutil uses MediaQuery to get the screen size, using MediaQuery will refresh the widget when the screen size changes, this problem causes the keyboard to refresh the widget when it pops up, I use LayoutBuilder to get the screen size instead to solve this problem, also I haven't used flutter_hooks, I can't give you advice sorry

janek515 commented 1 year ago

@842787863 Hi, thanks for your answer, I was able to figure it out, the solution in my case was here https://github.com/OpenFlutter/flutter_screenutil/issues/484#issuecomment-1590254340