Agent skill

Flutter Deactivate Setstate During Build

by divinevideo in divinevideo/divine-mobile

Fix "setState() or markNeedsBuild() called during build" error triggered from deactivate().

MPL-2.0Auto-check passedMobile

Install Flutter Deactivate Setstate During Build

skills CLI
$ npx skills add divinevideo/divine-mobile --skill flutter-deactivate-setstate-during-build -a claude-code

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

GitHub CLI
$ gh skill install divinevideo/divine-mobile flutter-deactivate-setstate-during-build --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-deactivate-setstate-during-build .claude/skills/flutter-deactivate-setstate-during-build && 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-deactivate-setstate-during-build
GitHub stars
266
Token cost
~938 tokens
SKILL.md length
264 words
Files
1
Skills in repo
103
Repo updated
First seen
Licence
MPL-2.0

At a glance

Fix "setState() or markNeedsBuild() called during build" error triggered from deactivate().

  • Works in 4 steps: Why deactivate() is problematic: It's… → Why dispose() doesn't have this issue:… → Capture references early: Get… → …
  • Error occurs during widget disposal
  • SKILL.md covers Problem, Context / Trigger Conditions, Solution and Key Insights, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Flutter Deactivate Setstate During Build is an agent skill from divinevideo/divine-mobile. Fix "setState() or markNeedsBuild() called during build" error triggered from deactivate(). Use when: (1) Error occurs during widget disposal or navigation away, (2) Stack trace shows deactivate - some notifier - ValueListenableBuilder.valueChanged, (3) Video/audio player pause() or stop() calls in deactivate() cause the error. The fix is deferring state-modifying operations to addPostFrameCallback.

Its SKILL.md is about 940 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 and Debugging. It works with Flutter. The licence is MPL-2.0.

When your agent uses it

  • Error occurs during widget disposal
  • Navigation away
  • Stack trace shows deactivate - some notifier - ValueListenableBuilder.valueChanged
  • Video/audio player pause()

Example prompts

  • “setState() or markNeedsBuild() called during build”
  • “/flutter-deactivate-setstate-during-build”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. Why deactivate() is problematic: It's called during the widget tree teardown phase,
  2. Why dispose() doesn't have this issue: By dispose(), the widget is fully unmounted
  3. Capture references early: Get controller/state references before the async gap
  4. Guard against double-execution: Check isPlaying again in the callback since

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

    No URLs in SKILL.md.

    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 Deactivate Setstate During Build loads about 938 tokens when it runs. Until then it costs about 112 tokens; SKILL.md has 264 words of instructions outside code blocks.

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

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). 264 words, ~938 tokens.

Download SKILL.mdSave it as .claude/skills/flutter-deactivate-setstate-during-build/SKILL.md (or your agent's skills folder).
name
flutter-deactivate-setstate-during-build
description
Fix "setState() or markNeedsBuild() called during build" error triggered from deactivate(). Use when: (1) Error occurs during widget disposal or navigation away, (2) Stack trace shows deactivate -> some notifier -> ValueListenableBuilder._valueChanged, (3) Video/audio player pause() or stop() calls in deactivate() cause the error. The fix is deferring state-modifying operations to addPostFrameCallback.
author
Claude Code
version
1.0.0
date
2025-01-27

Flutter: setState During Build from deactivate()

Problem

When navigating away from a screen, calling methods like VideoPlayerController.pause() in deactivate() triggers setState() or markNeedsBuild() called during build because the controller notifies its listeners synchronously during widget tree teardown.

Context / Trigger Conditions

  • Error: setState() or markNeedsBuild() called during build
  • Stack trace includes:
    • YourWidget.deactivate
    • VideoPlayerController.pause (or similar)
    • ChangeNotifier.notifyListeners
    • ValueListenableBuilder._valueChanged
  • Widget using ValueListenableBuilder<VideoPlayerValue> or similar
  • Trying to pause/stop media playback when navigating away

Solution

Defer the state-modifying operation to after the current frame:

dart
@override
void deactivate() {
  // Capture controller reference while ref/context is still valid
  final controller = _getController();

  // Defer pause to after current frame
  if (controller != null && controller.value.isPlaying) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (controller.value.isPlaying) {
        controller.pause();
      }
    });
  }

  super.deactivate();
}

Key Insights

  1. Why deactivate() is problematic: It's called during the widget tree teardown phase, which is part of the build process. Any synchronous notification to listeners will trigger rebuilds during build.

  2. Why dispose() doesn't have this issue: By dispose(), the widget is fully unmounted and listeners are typically already removed.

  3. Capture references early: Get controller/state references before the async gap since ref, context, or other widget state may become invalid.

  4. Guard against double-execution: Check isPlaying again in the callback since state may have changed.

Verification

  • Navigate away from the screen multiple times
  • No error in console
  • Video/audio properly pauses when leaving

Example: Full Implementation

dart
class _FullscreenVideoScreenState extends ConsumerState<FullscreenVideoScreen> {
  @override
  void deactivate() {
    _schedulePauseCurrentVideo();
    super.deactivate();
  }

  void _schedulePauseCurrentVideo() {
    final controller = _getCurrentController();
    if (controller == null || !controller.value.isInitialized) {
      return;
    }

    // Defer to avoid setState during build
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (controller.value.isPlaying) {
        controller.pause();
      }
    });
  }
}

Notes

  • This pattern applies to any ChangeNotifier that updates synchronously
  • Also relevant for: AnimationController.stop(), TextEditingController updates
  • If you need the pause to happen immediately (rare), consider using controller.pause() without notifying, though this breaks the observer pattern
  • The same issue can occur in didUpdateWidget when old controllers are disposed
  • Use deactivate() for cleanup that needs ref/context (like unsubscribing)
  • Use dispose() for cleanup that doesn't (like disposing controllers you own)
  • Never call setState() in deactivate() or dispose()

© 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-deactivate-setstate-during-build of divinevideo/divine-mobile.

Open the folder on GitHubat commit 4c622be

Compare with similar skills

Flutter Deactivate Setstate During Build 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 Deactivate Setstate During Build compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Flutter Deactivate Setstate During Build this skilldivinevideo/divine-mobile266—~938Automated safety check: PassMPL-2.0
Test Flet Apps Devflet-dev/flet17k—~1.3kAutomated safety check: PassApache-2.0
Frb Develop Featurefzyzcjy/flutter_rust_bridge5.4k—~2.3kAutomated safety check: PassMIT
Winapp CLIboshi-xixixi/TraeSkill275—~1.9kAutomated safety check: PassMIT
Debugging SurveysPostHog/posthog40k—~7.1kAutomated safety check: PassCustom licence
Frb Issue To Green PRfzyzcjy/flutter_rust_bridge5.4k—~1.8kAutomated safety check: PassMIT

Similar skills

  • Test Flet Apps Dev

    flet-dev/flet

    A skill your agent uses when testing or debugging Flet apps in maintainer/contributor development mode with local Python package sources and the local Flutter client, including web, desktop…

    17k GitHub stars~1.3k tokensUpdated today
    MobileAuto-check passed
  • Frb Develop Feature

    fzyzcjy/flutter_rust_bridge

    A skill your agent uses when fixing bugs, adding regression tests, adding new features, when compilation is slow, or when learning twin test naming conventions in flutterrustbridge

    5.4k GitHub stars~2.3k tokensUpdated yesterday
    MobileAuto-check passed
  • Winapp CLI

    boshi-xixixi/TraeSkill

    Windows App Development CLI (winapp) for building, packaging, signing, debugging, and UI-automating Windows applications.

    275 GitHub stars~1.9k tokensUpdated 4 mo ago
    MobileAuto-check passed
  • Debugging Surveys

    PostHog/posthog

    Official

    Diagnose PostHog Surveys configuration and responses across all five SDKs (web/posthog-js, iOS, Android, Flutter, React Native).

    40k GitHub stars~7.1k tokensUpdated today
    MobileAuto-check passed
  • Frb Issue To Green PR

    fzyzcjy/flutter_rust_bridge

    A skill your agent uses when implementing a GitHub issue, bug fix, or feature in flutterrustbridge end-to-end: develop the change, add regression coverage, prepare and open a PR, and use the user's…

    5.4k GitHub stars~1.8k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • 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

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 today
    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 today
    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 today
    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 today
    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 today
    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 today
    Auto-check passed

Works with

Categories

Questions about Flutter Deactivate Setstate During Build

What does Flutter Deactivate Setstate During Build do?

Fix "setState() or markNeedsBuild() called during build" error triggered from deactivate(). Flutter Deactivate Setstate During Build is an agent skill from divinevideo/divine-mobile. Fix "setState() or markNeedsBuild() called during build" error triggered from deactivate().

When should I use Flutter Deactivate Setstate During Build?

Flutter Deactivate Setstate During Build fits situations like: error occurs during widget disposal; navigation away; stack trace shows deactivate - some notifier - ValueListenableBuilder.valueChanged; video/audio player pause().

How do I install Flutter Deactivate Setstate During Build in Claude Code?

Run `npx skills add divinevideo/divine-mobile --skill flutter-deactivate-setstate-during-build -a claude-code`. Or copy the skill folder (.agents/skills/flutter-deactivate-setstate-during-build in divinevideo/divine-mobile) into .claude/skills/flutter-deactivate-setstate-during-build in your project. Claude Code loads it when a task matches its description.

How do I install Flutter Deactivate Setstate During Build in Codex?

Run `npx skills add divinevideo/divine-mobile --skill flutter-deactivate-setstate-during-build -a codex`. Or copy the skill folder (.agents/skills/flutter-deactivate-setstate-during-build in divinevideo/divine-mobile) into .agents/skills/flutter-deactivate-setstate-during-build in your project. Codex loads it when a task matches its description.

Can I use Flutter Deactivate Setstate During Build 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-deactivate-setstate-during-build -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-deactivate-setstate-during-build, .gemini/skills/flutter-deactivate-setstate-during-build, .github/skills/flutter-deactivate-setstate-during-build and .opencode/skills/flutter-deactivate-setstate-during-build in your project.

What does Flutter Deactivate Setstate During Build need to run?

SKILL.md names no scripts, command-line tools or credentials: Flutter Deactivate Setstate During Build is instructions for the agent only.

Does Flutter Deactivate Setstate During Build access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Flutter Deactivate Setstate During Build 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 Deactivate Setstate During Build use?

Flutter Deactivate Setstate During Build 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 Deactivate Setstate During Build use?

About 938 tokens (SKILL.md is roughly 3.8k 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 Deactivate Setstate During Build?

Skills that share tags, products or a category with Flutter Deactivate Setstate During Build: Test Flet Apps Dev (flet-dev/flet, 17k stars), Frb Develop Feature (fzyzcjy/flutter_rust_bridge, 5.4k stars), Winapp CLI (boshi-xixixi/TraeSkill, 275 stars) and Debugging Surveys (PostHog/posthog, 40k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Flutter Deactivate Setstate During Build?

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.