DEV Community

Curtly Critchlow
Curtly Critchlow

Posted on

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.

Top comments (0)