Agent skill

Flutter Pageview Scroll Position Preservation

by divinevideo in divinevideo/divine-mobile

Fix Flutter PageView "snap back" or scroll position reset issues on provider/state rebuilds.

MPL-2.0Auto-check passedMobile

Install Flutter Pageview Scroll Position Preservation

skills CLI
$ npx skills add divinevideo/divine-mobile --skill flutter-pageview-scroll-position-preservation -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install divinevideo/divine-mobile flutter-pageview-scroll-position-preservation --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/divinevideo/divine-mobile.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/flutter-pageview-implicit-scrolling-snapback .claude/skills/flutter-pageview-scroll-position-preservation && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
flutter-pageview-scroll-position-preservation
GitHub stars
266
Token cost
~1.2k tokens
SKILL.md length
291 words
Files
1
Skills in repo
103
Repo updated
First seen
Licence
MPL-2.0

At a glance

Fix Flutter PageView "snap back" or scroll position reset issues on provider/state rebuilds.

  • Works in 4 steps: Add PageStorageKey (PRIMARY FIX) → Keep PageController in State (not build) → Ensure keepPage is true (default) → …
  • PageView scrolls then snaps back to previous page after state update
  • SKILL.md covers Problem, Context / Trigger Conditions, Root Cause and Solution, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Flutter Pageview Scroll Position Preservation is an agent skill from divinevideo/divine-mobile. Fix Flutter PageView "snap back" or scroll position reset issues on provider/state rebuilds. Use when: (1) PageView scrolls then snaps back to previous page after state update, (2) Scroll position resets when Riverpod/Provider rebuilds, (3) Feed scrolls back to top on data refresh, (4) PageView loses position after orientation change or widget rebuild.

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering Cross-platform mobile apps. It works with Flutter. The licence is MPL-2.0.

When your agent uses it

  • PageView scrolls then snaps back to previous page after state update
  • Scroll position resets when Riverpod/Provider rebuilds
  • Feed scrolls back to top on data refresh
  • PageView loses position after orientation change

Example prompts

  • “snap back”
  • “/flutter-pageview-scroll-position-preservation”

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. Add PageStorageKey (PRIMARY FIX)
  2. Keep PageController in State (not build)
  3. Ensure keepPage is true (default)
  4. For complex state: Use PageStorage widget

What it can do on your machine

Read from SKILL.md and the folder at commit 4c622be. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are dart).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • api.flutter.dev
    • medium.com
    • github.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Flutter Pageview Scroll Position Preservation loads about 1.2k tokens when it runs. Until then it costs about 100 tokens; SKILL.md has 291 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~100
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from divinevideo/divine-mobile at commit 4c622be, republished under its MPL-2.0 licence (© divinevideo). 291 words, ~1,185 tokens.

Download SKILL.mdSave it as .claude/skills/flutter-pageview-scroll-position-preservation/SKILL.md (or your agent's skills folder).
name
flutter-pageview-scroll-position-preservation
description
Fix Flutter PageView "snap back" or scroll position reset issues on provider/state rebuilds. Use when: (1) PageView scrolls then snaps back to previous page after state update, (2) Scroll position resets when Riverpod/Provider rebuilds, (3) Feed scrolls back to top on data refresh, (4) PageView loses position after orientation change or widget rebuild.
author
Claude Code
version
1.1.0
date
2026-01-31

Flutter PageView Scroll Position Preservation

Problem

Users scrolling through a PageView-based feed report that the scroll position resets or "snaps back" to a previous page, especially after state updates from providers (Riverpod, Provider, BLoC) or widget rebuilds.

Context / Trigger Conditions

  • PageView with dynamic content from state management
  • Provider/Riverpod state updates causing widget rebuilds
  • Pagination that changes itemCount
  • Orientation changes
  • Tab switching and returning to the PageView

Root Cause

When Flutter rebuilds the widget tree (due to state changes), the PageView may lose its scroll position if:

  1. No PageStorageKey is provided to persist state
  2. The PageController is recreated during rebuilds
  3. PageController.keepPage is set to false

Note: allowImplicitScrolling is for accessibility focus navigation, NOT scroll position preservation. A specific bug (#76569) involving TextField focus was fixed in Flutter.

Solution

1. Add PageStorageKey (PRIMARY FIX)
dart
PageView.builder(
  // This key tells Flutter to persist scroll state across rebuilds
  key: const PageStorageKey<String>('my_page_view'),
  itemCount: videos.length,
  controller: _pageController,
  ...
)
2. Keep PageController in State (not build)
dart
class _MyScreenState extends State<MyScreen> {
  // Create in initState, NOT in build()
  late PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();  // Created once
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // Use the same controller instance
    return PageView.builder(
      controller: _pageController,
      ...
    );
  }
}
3. Ensure keepPage is true (default)
dart
_pageController = PageController(
  keepPage: true,  // This is the default, but be explicit if needed
  initialPage: 0,
);
4. For complex state: Use PageStorage widget
dart
PageStorage(
  bucket: PageStorageBucket(),
  child: PageView.builder(
    key: const PageStorageKey<String>('feed'),
    ...
  ),
)

What allowImplicitScrolling Actually Does

This is for accessibility, not scroll position:

  • false (default): Accessibility focus exits PageView at page boundaries
  • true: Accessibility focus moves to next page instead of exiting widget

It does NOT cause scroll position issues. Keep it true for better accessibility.

Verification

  1. Scroll to page 10+ in the feed
  2. Trigger a state update (like new data arriving)
  3. Verify scroll position is preserved
  4. Rotate device - verify position preserved
  5. Switch tabs and return - verify position preserved

Example

Full pattern for a Riverpod-based feed:

dart
class _VideoFeedScreenState extends ConsumerState<VideoFeedScreen> {
  late PageController _pageController;

  @override
  void initState() {
    super.initState();
    _pageController = PageController();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final videos = ref.watch(videoFeedProvider);

    return PageView.builder(
      key: const PageStorageKey<String>('video_feed'),
      controller: _pageController,
      itemCount: videos.length,
      allowImplicitScrolling: true,  // For accessibility
      itemBuilder: (context, index) => VideoItem(videos[index]),
    );
  }
}

Notes

  • The Riverpod 3.2.0 issue #4661 about ProviderScope rebuilds is separate
  • If using tabs, wrap in AutomaticKeepAliveClientMixin to preserve state
  • For very long lists, consider using restorationId for app restart persistence

References

© divinevideo, MPL-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/flutter-pageview-implicit-scrolling-snapback of divinevideo/divine-mobile.

Open the folder on GitHubat commit 4c622be

Compare with similar skills

Flutter Pageview Scroll Position Preservation next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Flutter Pageview Scroll Position Preservation compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Flutter Pageview Scroll Position Preservation this skilldivinevideo/divine-mobile266—~1.2kAutomated safety check: PassMPL-2.0
Add Flutter Docusaurus Localematthiasn/lotti1.2k—~1.2kAutomated safety check: PassGPL-3.0
Tm Launcher DesignFar-Se/tabame372—~3.1kAutomated safety check: PassMIT
Mobile App UI Designceorkm/mobile-app-ui-design400—~2kAutomated safety check: PassNone
Marionette Flutter Drive Appleancodepl/marionette_mcp473—~11kAutomated safety check: PassApache-2.0
Flutter ScreenshotJustLookAtNow/pt_mate503—~511Automated safety check: PassMIT

Similar skills

  • Add, complete, or audit a locale across a Flutter application's ARB catalogs and a localized Docusaurus manual, including generated localization code, locale selectors, native platform declarations…

    1.2k GitHub stars~1.2k tokensUpdated yesterday
    MobileAuto-check passed
  • Tm Launcher Design

    Far-Se/tabame

    Create or revise Tabame's Flutter launcher designs: frames, search bars, result rows, palettes, typography, and action dialogs.

    372 GitHub stars~3.1k tokensUpdated yesterday
    MobileAuto-check passed
  • Mobile App UI Design

    ceorkm/mobile-app-ui-design

    Design high-quality mobile app UI/UX screens, flows, and components.

    400 GitHub stars~2k tokensUpdated 3 mo ago
    MobileAuto-check passed
  • Marionette Flutter Drive App

    leancodepl/marionette_mcp

    Set up and drive a running Flutter app (debug or profile) with Marionette — an AI agent's hands and eyes for the app.

    473 GitHub stars~11k tokensUpdated 3 days ago
    MobileAuto-check passed
  • Flutter Screenshot

    JustLookAtNow/pt_mate

    Capture and show two Flutter UI screenshots for this project: one landscape/large-screen preview and one portrait/mobile preview, without using Flutter Web.

    503 GitHub stars~511 tokensUpdated 3 days ago
    MobileAuto-check passed
  • Flutter Init

    bear2u/my-skills

    A skill your agent uses when user wants to create a new Flutter project (Todo/Habit/Note/Expense/Custom domain) with Clean Architecture, Riverpod 3.0, Drift, and modern Flutter stack

    933 GitHub stars~2.5k tokensUpdated 3 mo ago
    MobileAuto-check passed

More from divinevideo/divine-mobile

All 103 skills in this repo
  • Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y".

    266 GitHub stars~931 tokensUpdated yesterday
    Auto-check passed
  • Art Direct

    divinevideo/divine-mobile

    Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language.

    266 GitHub stars~4.8k tokensUpdated yesterday
    Auto-check passed
  • Async Await Null Race Condition

    divinevideo/divine-mobile

    Fix "Null check operator used on a null value" errors when an object is set to null during an async await.

    266 GitHub stars~881 tokensUpdated yesterday
    Auto-check passed
  • AWS V4 Signing Custom Headers Gcs

    divinevideo/divine-mobile

    Add custom metadata headers (x-amz-meta-) to AWS v4 signed requests for GCS S3-compatible API.

    266 GitHub stars~1k tokensUpdated yesterday
    Auto-check passed
  • Bash Herestring Newline Secrets

    divinevideo/divine-mobile

    Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings.

    266 GitHub stars~791 tokensUpdated yesterday
    Auto-check passed
  • Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp).

    266 GitHub stars~1.1k tokensUpdated yesterday
    Auto-check passed

Works with

Categories

Questions about Flutter Pageview Scroll Position Preservation

What does Flutter Pageview Scroll Position Preservation do?

Fix Flutter PageView "snap back" or scroll position reset issues on provider/state rebuilds. Flutter Pageview Scroll Position Preservation is an agent skill from divinevideo/divine-mobile. Fix Flutter PageView "snap back" or scroll position reset issues on provider/state rebuilds.

When should I use Flutter Pageview Scroll Position Preservation?

Flutter Pageview Scroll Position Preservation fits situations like: pageView scrolls then snaps back to previous page after state update; scroll position resets when Riverpod/Provider rebuilds; feed scrolls back to top on data refresh; pageView loses position after orientation change.

How do I install Flutter Pageview Scroll Position Preservation in Claude Code?

Run `npx skills add divinevideo/divine-mobile --skill flutter-pageview-scroll-position-preservation -a claude-code`. Or copy the skill folder (.agents/skills/flutter-pageview-implicit-scrolling-snapback in divinevideo/divine-mobile) into .claude/skills/flutter-pageview-scroll-position-preservation in your project. Claude Code loads it when a task matches its description.

How do I install Flutter Pageview Scroll Position Preservation in Codex?

Run `npx skills add divinevideo/divine-mobile --skill flutter-pageview-scroll-position-preservation -a codex`. Or copy the skill folder (.agents/skills/flutter-pageview-implicit-scrolling-snapback in divinevideo/divine-mobile) into .agents/skills/flutter-pageview-scroll-position-preservation in your project. Codex loads it when a task matches its description.

Can I use Flutter Pageview Scroll Position Preservation in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add divinevideo/divine-mobile --skill flutter-pageview-scroll-position-preservation -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/flutter-pageview-scroll-position-preservation, .gemini/skills/flutter-pageview-scroll-position-preservation, .github/skills/flutter-pageview-scroll-position-preservation and .opencode/skills/flutter-pageview-scroll-position-preservation in your project.

What does Flutter Pageview Scroll Position Preservation need to run?

SKILL.md names no scripts, command-line tools or credentials: Flutter Pageview Scroll Position Preservation is instructions for the agent only.

Does Flutter Pageview Scroll Position Preservation access the network?

SKILL.md names 3 domains. As links in the text: api.flutter.dev, medium.com and github.com. This is read from the text; nothing was executed.

Is Flutter Pageview Scroll Position Preservation safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Flutter Pageview Scroll Position Preservation use?

Flutter Pageview Scroll Position Preservation is published under the MPL-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Flutter Pageview Scroll Position Preservation use?

About 1.2k tokens (SKILL.md is roughly 4.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Flutter Pageview Scroll Position Preservation?

Skills that share tags, products or a category with Flutter Pageview Scroll Position Preservation: Add Flutter Docusaurus Locale (matthiasn/lotti, 1.2k stars), Tm Launcher Design (Far-Se/tabame, 372 stars), Mobile App UI Design (ceorkm/mobile-app-ui-design, 400 stars) and Marionette Flutter Drive App (leancodepl/marionette_mcp, 473 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Flutter Pageview Scroll Position Preservation?

divinevideo (a GitHub organization) maintains it in divinevideo/divine-mobile, which has 266 GitHub stars. The repository holds 103 skills in this directory. The repository was last updated on October 8, 2026.

Source: divinevideo/divine-mobile on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.