DEV Community

Curtly Critchlow
Curtly Critchlow

Posted on

1

Why using form fields as descendants of a Listview is a bad idea - #100DaysOfCode - Day 22

Introduction

This post is part of my 100DaysOfCode series. In this series, I write about what I am learning on the 100DaysOfCode challenge. For this challenge, I will be learning flutter and firebase by building an Agriculture Management Information System.

Recap

On Day 21 we mainly discussed the difficulty I had with writing widget tests for my Flutter app.

Overview

In this post, we will discuss why using form fields as descendants of a Listview is a bad idea.

ListView Gotcha

ListView is a scrolling widget that displays its children one by one. When a child is scrolled out of view, the associated element subtree, states and render objects are destroyed. The means that user input from widgets like TextFormField will be lost when the widget is scrolled out of view. While they are ways to keep state mentioned here, I prefer to use a SingleChildScrollView with a row or column as its child to accommodate multiple widgets as shown below.

SingleChildScrollView(child:Column(children:yourFormChildren)); solution from stackoverflow

Wrap Up

In this post, we discussed why using form fields as descendants of a ListView is a bad idea.

Connect with me

Thank you for reading my post. Feel free to subscribe below to join me on the #100DaysOfCodeChallenge or connect with me on LinkedIn and Twitter. You can also buy me a book to show your support.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay