Skip to content

[ Widget Preview ] Null assertion failure when adding @Preview() to unsupported AST nodes #173959

Closed

Description

@bkonyi

flutter widget-preview start will currently crash on 3.35.{0,1} if the @Preview() annotation is added to an AST node that isn't part of a valid preview.

For example, adding @Preview() to a class declaration will cause the following crash:

Thread 0 main thread_TypeError: Null check operator used on a null value
at _PreviewVisitor.visitAnnotation(dependency_graph.dart:108)
at AnnotationImpl.accept(ast.dart:366)
at NodeListImpl.accept(ast.dart:13243)
at _AnnotatedNodeMixin._visitCommentAndAnnotations(ast.dart:19496)
at AnnotatedNodeImpl.visitChildren(ast.dart:165)
at ClassDeclarationImpl.visitChildren(ast.dart:2939)
at RecursiveAstVisitor.visitClassDeclaration(visitor.dart:940)
at ClassDeclarationImpl.accept(ast.dart:2935)
at NodeListImpl.accept(ast.dart:13243)
at CompilationUnitImpl.visitChildren(ast.dart:3611)
at LibraryPreviewNode.findPreviews(dependency_graph.dart:185)
at PreviewDetector._findPreviewFunctions(preview_detector.dart:202)
at <asynchronous gap>(async)
at PreviewDetector.initialize(preview_detector.dart:54)
at <asynchronous gap>(async)
at WidgetPreviewStartCommand.runCommand(widget_preview.dart:305)
at <asynchronous gap>(async)
at FlutterCommand.run.<anonymous closure>(flutter_command.dart:1581)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:154)
at <asynchronous gap>(async)
at CommandRunner.runCommand(command_runner.dart:212)
at <asynchronous gap>(async)
at FlutterCommandRunner.runCommand.<anonymous closure>(flutter_command_runner.dart:503)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:154)
at <asynchronous gap>(async)
at FlutterCommandRunner.runCommand(flutter_command_runner.dart:438)
at <asynchronous gap>(async)
at run.<anonymous closure>.<anonymous closure>(runner.dart:98)
at <asynchronous gap>(async)
at AppContext.run.<anonymous closure>(context.dart:154)
at <asynchronous gap>(async)
at main(executable.dart:101)
at <asynchronous gap>(async)

Annotated nodes that aren't valid previews should be ignored.

This is a top 10 crasher for the tool for 3.35.{0,1}.

Activity

  1. self-assigned this
    on Aug 18, 2025
  2. added
    P1High-priority issues at the top of the work list
    team-toolOwned by Flutter Tool team
    triaged-toolTriaged by Flutter Tool team
    a: widget previewsIssues related to the Widget Previewer tooling
    on Aug 18, 2025
  3. github-actions commented on Sep 4, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: widget previewsIssues related to the Widget Previewer toolingteam-toolOwned by Flutter Tool teamtriaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions