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

Textfield in gallery gets reset if scrolled out of view #11500

Closed
BenSower opened this issue Aug 3, 2017 · 54 comments
Closed

Textfield in gallery gets reset if scrolled out of view #11500

BenSower opened this issue Aug 3, 2017 · 54 comments
Labels
a: text input Entering text in a text field or keyboard related problems c: dataloss Can result in the user losing their state customer: gallery Relating to flutter/gallery repository. Please transfer non-framework issues there. d: examples Sample code and demos framework flutter/packages/flutter repository. See also f: labels.

Comments

@BenSower
Copy link

BenSower commented Aug 3, 2017

Steps to Reproduce

  1. Use a device with a display similar to an Galaxy S5 SM G900F
  2. Open the "Gallery > Text Fields"
  3. Enter some text in the first field
  4. Tap into the next field and scroll the first field out of view
  5. Scroll it back into view
    --> The first field is reset

As a solution I think adding a TextEditingController to the fields might suffice.

Logs

No notable logs

Flutter Doctor

[✓] Flutter (on Linux, locale en_US.UTF-8, channel master)
    • Flutter at /home/ben/Desktop/Dev/flutter/flutter
    • Framework revision 58f47bd906 (8 hours ago), 2017-08-02 17:34:23 -0700
    • Engine revision 1de56a33d2
    • Tools Dart version 1.25.0-dev.7.0

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
    • Android SDK at /home/ben/Android/Sdk
    • Platform android-25, build-tools 25.0.3
    • Java binary at: /usr/local/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Android Studio (version 2.3)
    • Android Studio at /usr/local/android-studio
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] Connected devices
    • SM G900F • 118f97ca • android-arm • Android 6.0.1 (API 23)

Steps:
flutter_01
flutter_02
flutter_03

@eseidelGoogle
Copy link
Contributor

@Hixie did some work around keeping alive offscreen widgets in scroll views. Its possible the gallery example is just missing the proper calls.

@BenSower
Copy link
Author

BenSower commented Aug 3, 2017

Yeah, my TextEditorController proposition was mostly based on this discussion: https://stackoverflow.com/questions/45240734/flutter-form-data-disappears-when-i-scroll

@jandado
Copy link

jandado commented Aug 7, 2017

Hi everyone, we are experiencing same behavior with TextFormFiled as well as ExpansionTile widgets - when scrolled off screen in a ListView, both lose state.
The suggested workaround - to set a controller on a TextField does not work on ExpansionTile (setting onExpansionChanged) does not resolve the issue.

@eseidelGoogle , could you point us at the code @Hixie may have touched (in regards to "keeping alive offscreen widgets") that may need fixing? Cheers!

@Hixie
Copy link
Contributor

Hixie commented Aug 15, 2017

From @rickbsgu on #11629:

You can see this with the 'Text fields' sub-app in the 'Gallery' app. Pop up a keyboard, enter values, scroll around. Happens on iOS and Android. Hidden/scrolled out fields get set back to their initial value(s).

This seems to be a bug or incomplete implementation. I would think a normal expectation would be to create the form and whatever values are entered in the fields while the form is active should remain until the form is either submitted or dismissed (or initial values explicitly restored.) You shouldn't have to do anything out of the ordinary to preserve values through scrolling/keyboard popups or whatever else might inadvertently destroy the fields while using it (the form.)

If otherwise, the demo needs to be beefed up to show how to preserve values through scrolling/hiding/other operations while the form is active.

@rickbsgu
Copy link

Creating a TextEditorController only works with TextFormFields. A more generic solution is needed for other FormField derivations.

@rickbsgu
Copy link

I've posted one approach to this on the discussion board:

Flutter Form persistence + example RadioTile FormField derivation

@Hixie
Copy link
Contributor

Hixie commented Aug 18, 2017

(It would be much more convenient if the patches you wanted people to review were online e.g. on GitHub rather than in a zip file that had to be locally uncompressed, opened, etc.)

@rickbsgu
Copy link

rickbsgu commented Aug 19, 2017

This is worse than I thought. Turns out that if a field is hidden (deleted), 'onSave()' doesn't get called, either, nor does any supplied validator function (because it's deleted -- the Form class doesn't know anything about it, anymore.)

For the 'onSave()' issue, the answer is to get values from a persister mechanism and not supply an 'onSave()' function.

I suspect the validator issue will require a similar approach. The question is how to forward error state when the field gets re-instantiated.

My working example repo that supplies a persister mechanism is here: https://github.com/rickbsgu/rbtile_formfield_demo.git. Note that it pulls https://github.com/rickbsgu/form_fields.git as a dependency.

@rickbsgu
Copy link

rickbsgu commented Aug 19, 2017

Ok, I came up with a solution to make sure a FormField validator() is called when a FormField instance is re-instantiated. The FormField checks the owning Form autostate value (which persists across FormField drops and re-instantiations) and calls the validator directly if it's set.

Unfortunately, I can't make that work with TextFormField, so I cloned it and created a working version as TextInputFormField with the check and validation call in the builder call.

So, this solution keeps the validator with the field, rather than having to create yet another level of indirection by having to place it in the persister.

With all that, I finally seem to have a Form that behaves as I would expect it to.

@rickbsgu
Copy link

rickbsgu commented Aug 20, 2017

So, thinking more on this, I would suggest what is needed is a class that encapsulates all of this - something like 'FormPage' or 'FormView'. It would contain a form and the persisters (and perhaps a FocusNode).

If the whole thing were self-contained, it would be much easier for users (me :) )to deal with.

@Hixie Hixie added framework flutter/packages/flutter repository. See also f: labels. a: text input Entering text in a text field or keyboard related problems c: dataloss Can result in the user losing their state labels Oct 7, 2017
@Hixie Hixie added this to the 3: Current Milestone milestone Oct 7, 2017
@Mahi-K
Copy link

Mahi-K commented Nov 20, 2017

Hi there,
I think you can simply solve this by assigning an initialValue to the TextFormField i.e., initialValue: _controller.text,

but, i am not so sure if this is of any help to you but obviously this should happen whenever a state builds the TextFormField.

Please, do let me know if you have any more suggestions or any other way to solve this issue.

@Hixie Hixie modified the milestones: 3: Current Milestone, 4: Next milestone Dec 20, 2017
@toregua
Copy link

toregua commented Jan 14, 2018

The problem when i use controller for TextFormField, it create another issue with all repos containing a form inside a listview.
You can reproduce with the repo of rickbsgu quoted just before here : https://github.com/rickbsgu/rbtile_formfield_demo.git

1> Fill the first field "Name".
2> Scroll directly to the last radio button on the bottom ignoring all forms between
3> Click for example on YES of the last radio button "Contact Parents?"
4> ERROR :

Performing full restart...
Syncing files to device ONEPLUS A5000...
Restarted app in 987ms.
W/IInputConnectionWrapper(15587): getCursorCapsMode on inactive InputConnection
I/flutter (15587): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (15587): The following assertion was thrown building NotificationListener<KeepAliveNotification>:
I/flutter (15587): 'package:flutter/src/rendering/object.dart': Failed assertion: line 2702 pos 14:
I/flutter (15587): '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
I/flutter (15587):
I/flutter (15587): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (15587): more information in this error message to help you determine and fix the underlying cause.
I/flutter (15587): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (15587):   https://github.com/flutter/flutter/issues/new
I/flutter (15587):
I/flutter (15587): When the exception was thrown, this was the stack:
I/flutter (15587): #2      RenderSliver&ContainerRenderObjectMixin._insertIntoChildList (package:flutter/src/rendering/object.dart:2702:14)
I/flutter (15587): #3      RenderSliver&ContainerRenderObjectMixin.insert (package:flutter/src/rendering/object.dart:2736:5)
I/flutter (15587): #4      RenderSliverMultiBoxAdaptor.insert (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:193:17)
I/flutter (15587): #5      SliverMultiBoxAdaptorElement.insertChildRenderObject (package:flutter/src/widgets/sliver.dart:840:18)
I/flutter (15587): #6      RenderObjectElement.attachRenderObject (package:flutter/src/widgets/framework.dart:4391:35)
I/flutter (15587): #7      RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4161:5)
I/flutter (15587): #8      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4531:16)
I/flutter (15587): #9      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2857:14)
I/flutter (15587): #10     Element.updateChild (package:flutter/src/widgets/framework.dart:2660:12)
I/flutter (15587): #11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #12     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #13     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3524:5)
I/flutter (15587): #14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3519:5)
I/flutter (15587): #15     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2857:14)
I/flutter (15587): #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2660:12)
I/flutter (15587): #17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #18     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #19     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3524:5)
I/flutter (15587): #20     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3519:5)
I/flutter (15587): #21     ParentDataElement.mount (package:flutter/src/widgets/framework.dart:3837:16)
I/flutter (15587): #22     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2857:14)
I/flutter (15587): #23     Element.updateChild (package:flutter/src/widgets/framework.dart:2660:12)
I/flutter (15587): #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #25     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #26     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3524:5)
I/flutter (15587): #27     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3662:22)
I/flutter (15587): #28     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3519:5)
I/flutter (15587): #29     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2857:14)
I/flutter (15587): #30     Element.updateChild (package:flutter/src/widgets/framework.dart:2660:12)
I/flutter (15587): #31     SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:696:34)
I/flutter (15587): #32     SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:665:7)
I/flutter (15587): #33     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #34     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #35     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #36     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4261:32)
I/flutter (15587): #37     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4647:17)
I/flutter (15587): #38     _ViewportElement.update (package:flutter/src/widgets/viewport.dart:182:17)
I/flutter (15587): #39     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #40     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #41     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #42     ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #43     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #44     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #45     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #46     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #47     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #48     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #49     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #50     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #51     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #52     StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #53     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #54     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #55     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #56     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #57     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #58     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #59     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #60     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #61     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #62     StatelessElement.update (package:flutter/src/widgets/framework.dart:3606:5)
I/flutter (15587): #63     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #64     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #65     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #66     StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #67     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #68     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #69     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #70     StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #71     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #72     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #73     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #74     StatelessElement.update (package:flutter/src/widgets/framework.dart:3606:5)
I/flutter (15587): #75     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #76     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #77     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #78     ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #79     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #80     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #81     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #82     StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #83     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #84     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #85     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #86     StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #87     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #88     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #89     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #90     ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #91     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #92     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4261:32)
I/flutter (15587): #93     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4647:17)
I/flutter (15587): #94     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #95     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #96     Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #97     ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #98     Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #99     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #100    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #101    ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #102    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #103    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4261:32)
I/flutter (15587): #104    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4647:17)
I/flutter (15587): #105    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #106    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #107    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #108    ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #109    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #110    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #111    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #112    StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #113    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #114    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #115    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #116    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #117    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #118    StatelessElement.update (package:flutter/src/widgets/framework.dart:3606:5)
I/flutter (15587): #119    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #120    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4539:14)
I/flutter (15587): #121    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #122    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #123    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #124    StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #125    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #126    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #127    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #128    StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #129    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #130    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #131    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #132    ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #133    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #134    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #135    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #136    ProxyElement.update (package:flutter/src/widgets/framework.dart:3791:5)
I/flutter (15587): #137    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #138    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #139    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #140    StatefulElement.update (package:flutter/src/widgets/framework.dart:3681:5)
I/flutter (15587): #141    Element.updateChild (package:flutter/src/widgets/framework.dart:2649:15)
I/flutter (15587): #142    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3556:16)
I/flutter (15587): #143    Element.rebuild (package:flutter/src/widgets/framework.dart:3445:5)
I/flutter (15587): #144    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2193:33)
I/flutter (15587): #145    BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:611:20)
I/flutter (15587): #146    BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:203:5)
I/flutter (15587): #147    BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:916:15)
I/flutter (15587): #148    BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:856:9)
I/flutter (15587): #149    BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:768:5)
I/flutter (15587): #150    _invoke (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:113)
I/flutter (15587): #151    _drawFrame (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:102)
I/flutter (15587): (elided 2 frames from class _AssertionError)
I/flutter (15587): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15587): Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 2702 pos 14: '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 2702 pos 14: '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 2702 pos 14: '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
I/flutter (15587): Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 3447 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.

I have exactly the same behavior inside my own project.

Do you have any ideas or workaround please ?

@nailgilaziev
Copy link

is there any progress on this topic?
my form has many TextFormField that can not be simultaneously displayed on the screen. When scrolling fields gets reset. What approach can I use for now? and what plans for this issue flutter team has?

@Hixie
Copy link
Contributor

Hixie commented Jan 22, 2018

One workaround is to maintain the TextEditingControllers for all the text fields, and make sure you reuse the same one each time for the same text field.

Another would be to liberally apply KeepAlive to the widgets you want to keep alive.

@vazad28
Copy link

vazad28 commented Feb 10, 2018

How can one create TextEditingControllers if using a map to create the form fields dynamically.

@Mahender-Prayuta
Copy link

hi @vazad28 , can you please elaborate on what you are trying to achieve? As i am not sure 'using a map to create the form fields dynamically'.

Many Thanks,
Mahi

@Mahender-Prayuta
Copy link

Hey, @toregua , have you got to solve the problem?

One workaround is to use the SingleChildScrollView with child as Column and include all your widgets in it then you might overcome this '_debugUltimatePreviousSiblingOf(after, equals: _firstChild)' error as the formfields are not removed from view as they are done inside a ListView. I've had the same problem and solved by building the widget as a SingleChildScrollView.

Many thanks,
Mahi.

@vazad28
Copy link

vazad28 commented Feb 10, 2018

this is what I'm trying

List<Widget> getTemplateFields() {
    List<Widget> _fieldWidgets = new List();

    for(var idx = 0; idx < _templateFieldList.length; idx++){
      switch (_templateFieldList[idx].type) {
        case 'text':
          _fieldWidgets.add(new ListTile(
            title: new TextFormField(
              keyboardType: TextInputType.text,
              style: Theme.of(context).textTheme.subhead,
              //labelText: globals.capitalize(_templateFieldList[idx].title),
              initialValue:
                  _caseData.fieldsData[_templateFieldList[idx].slug] ?? '',
              validator: (val){
                if(_autovalidate) formValidator.validateAlphaNum(val);  
                _caseData.fieldsData[_templateFieldList[idx].slug] = val;
              },
              onSaved: (newVal) => setState(() => _caseData
                      .fieldsData[_templateFieldList[idx].slug] = newVal)),
          ));
          break;
        case 'number':
          _fieldWidgets.add(new KeepAlive(
              key: new Key(_templateFieldList[idx].slug),
              keepAlive: true,
              child : new TextFormField(
                keyboardType: TextInputType.number,
                style: Theme.of(context).textTheme.subhead,
                controller: hasController[idx],
                // initialValue:
                //     _caseData.fieldsData[_templateFieldList[idx].slug] ?? '',
                decoration: new InputDecoration(
                    labelText: globals.capitalize(_templateFieldList[idx].title)),
                validator: (val){
                  print("validate val $val");
                  if(_autovalidate) formValidator.validateNumber(val);  
                  _caseData.fieldsData[_templateFieldList[idx].slug] = val;
                },
                onSaved: (newVal) => setState(() => _caseData
                    .fieldsData[_templateFieldList[idx].slug] = newVal)),
          ));
          break;
        case 'date':
          _fieldWidgets.add( new ListTile(
            title: new TextFormField(
                keyboardType: TextInputType.datetime,
                style: Theme.of(context).textTheme.subhead,
                initialValue:
                    _caseData.fieldsData[_templateFieldList[idx].slug] ?? '',
                decoration: new InputDecoration(
                    labelText: globals.capitalize(_templateFieldList[idx].title)),
                validator: formValidator.validateString,
                onSaved: (newVal) => setState(() => _caseData
                    .fieldsData[_templateFieldList[idx].slug] = newVal)),
          ));
          break;
.......

@Mahender-Prayuta
Copy link

Hi @vazad28 , I think you can just have a list for TextEditingControllers as well just like you did for the textfields.

@vazad28
Copy link

vazad28 commented Feb 10, 2018

I tried that too but value of the field still gets lost.
controller: hasController[idx],
hasController is a map of index and a new Controller in loop.

@Mahender-Prayuta
Copy link

oh sorry just use the textfield not the textformfield then you will be fine.

@vazad28
Copy link

vazad28 commented Feb 10, 2018

With textField alone, I can's use validator. Can I?

@Mahender-Prayuta
Copy link

Mahender-Prayuta commented Feb 10, 2018

yesyou can use validators as well its only a call back and you can do this in onChanged value

                     new TextField(
                    controller: _nameController,
                    focusNode: _nameFocusNode,
                    keyboardType: TextInputType.text,
                    autocorrect: false,
                   decoration: new InputDecoration(
                    labelText: 'Name *',
                     errorText: _nameFieldErrorText,
                           ),
                           onChanged: (String value) {
                                  if (!mounted) return;
                            setState(() {
                               (value.length > 0)
                                   ? _formWasEdited = true
                                : _formWasEdited = false;

                    customerDetailsModel.setCustomerName(value.trim());

                    var str = validateName(value);

                    (str == null)
                        ? _nameFieldErrorText = null
                        : _nameFieldErrorText = str;
                    if (widget.borrowerSnapShot.isNotEmpty) {
                      (existingCustomerName.trim() ==
                              _nameController.text.trim())
                          ? nameEdited = false
                          : nameEdited = true;
                    }
                  });
                  if (!(_nameController.text.isEmpty)) {
                    _formWasEdited = true;
                  }
                },
              ),
           String validateName(String value) {
              //  bool _formWasEdited = true;
                  if (value.isEmpty) return 'Name is required.';
                 final RegExp nameExp = new RegExp(r'^[A-Za-z ]+$');
               if (!nameExp.hasMatch(value))
                  return 'Please enter only alphabetical characters and spaces.';
               if (value.length > 25) {
               return 'Name cannot exceed 25 characters';
              }
               return null;
             }

make sure you initialize the _nameFieldErrorText = null; and just the string from your validation to _nameFieldErrorText like i did in validateName(value).

@acidjazz
Copy link

acidjazz commented May 14, 2018

What's the latest on this issue? Is there a workaround until it's solved?

Is the PR #15484 in the beta branch yet? Does it fix this? Or does it help a workaround of always providing an initial value?

@HansMuller
Copy link
Contributor

@acidjazz - PR #15484 was on version 2.8 (and later) of the beta branch: https://flutter.io/sdk-archive/#linux

@acidjazz
Copy link

acidjazz commented May 15, 2018

I've been trying to use PR #15484 as a solution to my inputs disappearing and reseting:

Above in my State class..

final List<TextEditingController> _controllers = new List.generate(5, (int n) {
    return new TextEditingController();

One of my TextFormField's:

new TextFormField(
  decoration: const InputDecoration(
    icon: const Icon(Icons.computer),
    labelText: 'FTP Host',
  ),
  validator: _validateField,
  initialValue: user.ftpHost,
  keyboardType: TextInputType.url,
  onSaved: (String value) {
    user.ftpHost = value;
  },
  controller: _controllers[0],
)

I keep getting

'package:flutter/src/material/text_form_field.dart': Failed assertion: line 72 pos 15: 'initialValue == null || controller == null': is not true.

Exception

I/flutter ( 8385): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 8385): The following assertion was thrown building Settings(dirty, state: SettingsState#47968):
I/flutter ( 8385): 'package:flutter/src/material/text_form_field.dart': Failed assertion: line 72 pos 15: 'initialValue
I/flutter ( 8385): == null || controller == null': is not true.
I/flutter ( 8385): 
I/flutter ( 8385): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 8385): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 8385): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 8385):   https://github.com/flutter/flutter/issues/new
I/flutter ( 8385): 
I/flutter ( 8385): When the exception was thrown, this was the stack:
I/flutter ( 8385): #2      new TextFormField (package:flutter/src/material/text_form_field.dart)
I/flutter ( 8385): #3      SettingsState.build (package:maxanet_uploader/pages/settings.dart:103:21)
I/flutter ( 8385): #4      StatefulElement.build (package:flutter/src/widgets/framework.dart:3722:27)
I/flutter ( 8385): #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3634:15)
I/flutter ( 8385): #6      Element.rebuild (package:flutter/src/widgets/framework.dart:3487:5)
I/flutter ( 8385): #7      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2234:33)
I/flutter ( 8385): #8      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:626:20)
I/flutter ( 8385): #9      _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter ( 8385): #10     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 8385): #11     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 8385): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter ( 8385): #13     _invoke (dart:ui/hooks.dart:120:13)
I/flutter ( 8385): #14     _drawFrame (dart:ui/hooks.dart:109:3)
I/flutter ( 8385): (elided 2 frames from class _AssertionError)
I/flutter ( 8385): ════════════════════════════════════════════════════════════════════════════════════════════════════

@Mahender-Prayuta
Copy link

Mahender-Prayuta commented May 16, 2018 via email

@acidjazz
Copy link

acidjazz commented May 17, 2018

thanks @Mahender-Prayuta that worked perfectly! Here is a sample of your solution so the next person w/ this issue can resolve it faster.

...
body: new Form(
  key: _formKey,
  child: new Container(
    padding: new EdgeInsets.symmetric(horizontal: 30.0, vertical: 30.0),
    child: SingleChildScrollView(
      child: new Column(
        children: <Widget>[
          new TextFormField(
            decoration: const InputDecoration(
              icon: const Icon(Icons.computer),
              labelText: 'FTP Host',
            ),
            validator: _validateField,
            initialValue: user.ftpHost,
            keyboardType: TextInputType.url,
            onSaved: (String value) {
              user.ftpHost = value;
            },
          ),
          new TextFormField(
            decoration: const InputDecoration(
              icon: const Icon(Icons.account_box),
              labelText: 'FTP Username',
            ),
            validator: _validateField,
            initialValue: user.ftpUsername,
            keyboardType: TextInputType.url,
            onSaved: (String value) {
              user.ftpUsername = value;
            },
          ),
...

@Hixie Hixie added customer: gallery Relating to flutter/gallery repository. Please transfer non-framework issues there. d: examples Sample code and demos labels Jun 12, 2018
@Hixie Hixie changed the title Textfield gets reset if scrolled out of view Textfield in gallery gets reset if scrolled out of view Jun 12, 2018
@Hixie
Copy link
Contributor

Hixie commented Jun 12, 2018

cc @HansMuller did we fix this for the gallery?

@HansMuller
Copy link
Contributor

Yes, the original Gallery bug (per the bug's description) was fixed with #15484

@androidvov
Copy link

@Mahender-Prayuta I solve this problem use SingleChildScrollView ,this is easy way to solve this problem.
But with ohter Stateful widget , you have to write some code to implement the child Stateful widget can notify the parent store the changed state for the next render .

@AparnaTumu
Copy link

@Mahender-Prayuta You are awsome 😄 👍

@langaro
Copy link

langaro commented Jul 5, 2019

@Mahender-Prayuta Thank you very vey very much.

@gabrielmcreynolds
Copy link

Is this being fixed as I'm still having this issue on the stable channel. For now I'm using @Mahender-Prayuta solution.

@Andrauss
Copy link

Andrauss commented Jul 8, 2020

I've facing this issue, solved replacing ListView to a SingleChildScrollView as suggested by @Mahender-Prayuta

@manishh
Copy link

manishh commented Jul 17, 2020

This issue is not yet fixed? It has been 3 years.....

I encountered it today, and used SingleChildScrollView to fix the problem as suggested.
But rather concerned about shipping my app with flutter now.

@babaker5755
Copy link

babaker5755 commented Oct 27, 2020

Adding AutomaticKeepAliveClientMixin to my component and using the wantKeepAlive property fixed my problem while still using ListView.

class _WidgetState extends State<Widget> with AutomaticKeepAliveClientMixin {
   @override
   bool get wantKeepAlive => true;
  }

https://api.flutter.dev/flutter/widgets/AutomaticKeepAliveClientMixin-mixin.html

@alfredozn
Copy link

alfredozn commented Dec 4, 2020

If you still have the problem. Or for those who are facing it recently:

You need to save your state before the list view recicle the textfields.
The onSaved method will be triggered only on form submission, so, you need to use onChanged
For instance:

      onSaved: (value) => setState(() =>_anObject.aProperty = value),
      onChanged: (value) => setState(() =>_anObject.aProperty = value),

@github-actions
Copy link

github-actions bot commented Aug 9, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: text input Entering text in a text field or keyboard related problems c: dataloss Can result in the user losing their state customer: gallery Relating to flutter/gallery repository. Please transfer non-framework issues there. d: examples Sample code and demos framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests