flutter-listview-viewport-gotchas

Diagnose Flutter viewport list recycling issues and preserve widget state.

6|Updated Apr 23, 2026
One-click install
npx skills add https://github.com/ImL1s/flutter-claude-skills --skill flutter-listview-viewport-gotchas
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flutter-listview-viewport-gotchas
Source: https://github.com/ImL1s/flutter-claude-skills/tree/main/skills/flutter-listview-viewport-gotchas
Command: npx skills add https://github.com/ImL1s/flutter-claude-skills --skill flutter-listview-viewport-gotchas

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

ListView, CustomScrollView, and GridView recycle off-screen widgets, causing disposed State and reinitialization after scrolling, which can lead to UI inconsistencies or missing updates.

Core Features & Use Cases

  • Debug patterns for didUpdateWidget not called, ScrollController hasClients false, and widgets being disposed during viewport recycling.
  • Guidance for preventing state loss when scrolling, including keep-alive strategies and safe scrolling to the selected item.
  • Real-world debugging scenarios that show how to reproduce and fix common viewport recycling issues in Flutter apps.

Quick Start

Open a Flutter project and apply the viewport debugging patterns to diagnose and fix ListView/CustomScrollView recycling issues.

Frequently Asked Questions about flutter-listview-viewport-gotchas

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my Flutter ListView lose widget state when scrolling?

Flutter ListView recycles off-screen widgets, causing disposed State and reinitialization after scrolling. Diagnose viewport recycling patterns by implementing initState and didUpdateWidget handlers to prevent stale state and UI inconsistencies during item recycling.

How do I fix didUpdateWidget not being called in a Flutter CustomScrollView?

When didUpdateWidget is not called in a CustomScrollView, the viewport has recycled the widget without triggering state updates. Apply viewport debugging patterns to implement proper didUpdateWidget handlers and guard against stale state during item recycling.

What's the best way to handle ScrollController hasClients false in horizontally scrolling lists?

When ScrollController.hasClients is false in horizontally scrolling lists, guard against missing clients before invoking scroll actions. Apply safe scrolling patterns to auto-scroll to the selected item only when clients are actively attached to preserve visible state.

How do I prevent state loss when scrolling items in a Flutter GridView?

To prevent state loss during GridView scrolling, employ keep-alive strategies that preserve widget state when items are recycled off-screen. Combine this with safe scrolling to the selected item to maintain visible state consistency across viewport boundaries.

When should I use keep-alive strategies in Flutter viewport-based lists?

Use keep-alive strategies in Flutter viewport-based lists when widget state disappears on scroll or when recycled items lose critical updates. These strategies preserve State objects during viewport recycling, preventing reinitialization and UI inconsistencies in ListView and CustomScrollView.