Giter Club home page Giter Club logo

flutter_form_stepper_bug's Introduction

flutter_form_stepper_bug

Issue I opened on the Flutter repo: flutter/flutter#115695

Problem

When working with a lengthy Form widget inside a Stepper widget with multiple Steps, only form fields visible are recognized. That leads to wrongfully ignoring methods called on those form fields.
This is especially problematic if, for example, you fill out a field in step 1, go to the last step, fill something out there and call .save(). If many steps are present, the value filled out in the top field will not be saved.

The Reason

The Material Stepper widget internally uses a ListView to show its Steps. ListView (in contrast to SingleChildScrollView) uses lazy loading for its items, which means that Steps currently not visible in the Stepper are ignored. In case of having FormFields inside the Steps, their methods (like .save()) are not called.

Minimal Reproducible Example

I created this repository to show the bug in a minimal reproducible way.
In form_stepper.dart, a Stepper with 10 Steps and 10 TextFormFields per Step is created.
The _savedFieldsPerStep map is used to showcase the problem: The .save() method of each TextFormField should increment the value for its step number as key. This means, when saving the form, each key of the map should have 10 as value.
However, what you will witness is that saving at the top will leave the bottom steps at 0 saved fields and vice versa.

Proposed Solution

A way to prevent the faulty lazy-loading mechanism of the Stepper would be to use SingleChildScrollView instead of ListView internally.
However, this would lead to problems with performance, especially for usages of the Stepper where lazy loading is actually desired.
Therefore, I propose to add a bool parameter to the Stepper widget, which allows to disable lazy loading and switch the internal ListView to a SingleChildScrollView with a Column as its child.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.