Skip to content

widget-preview crashes when serializing parameterized MultiPreview annotations due to a null constructorInvocation in DartObject.toExpression() #181754

Description

@hemandroid

Command

flutter widget-preview start

Steps to Reproduce

I have created a custom class by extending the MultiPreview to get multiple previews using custom device specs. Where the preview gives a feel like an emulator.

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';

enum Device { phone }

final class DevicePreview extends MultiPreview {
  const DevicePreview({required this.devices});

  final List<Device> devices;

  @override
  List<Preview> get previews {
    return devices.map(
      (d) => Preview(
        name: d.name,
        size: const Size(360, 780),
      ),
    ).toList();
  }
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  @DevicePreview(devices: [Device.phone])
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(body: Text('Hello')),
    );
  }
}

Result:

Found 1 preview
Null check operator used on a null value

Logs

_TypeError: (#0 _extension#0._createInstance (package:flutter_tools/src/widget_preview/preview_code_generator.dart:242:85))

#0      _extension#0._createInstance (package:flutter_tools/src/widget_preview/preview_code_generator.dart:242:85)
#1      _extension#0.toExpression (package:flutter_tools/src/widget_preview/preview_code_generator.dart:214:26)
#2      _extension#0._createInstance (package:flutter_tools/src/widget_preview/preview_code_generator.dart:255:21)
#3      _extension#0.toExpression (package:flutter_tools/src/widget_preview/preview_code_generator.dart:214:26)
#4      PreviewCodeGenerator._buildPreviews (package:flutter_tools/src/widget_preview/preview_code_generator.dart:193:46)
#5      PreviewCodeGenerator._buildGeneratedPreviewMethod (package:flutter_tools/src/widget_preview/preview_code_generator.dart:145:13)
#6      PreviewCodeGenerator.populatePreviewsInGeneratedPreviewScaffold.<anonymous closure>.<anonymous closure> (package:flutter_tools/src/widget_preview/preview_code_generator.dart:109:37)
#7      _$MethodBuilder.update (package:code_builder/src/specs/method.g.dart:332:33)
#8      new _$Method (package:code_builder/src/specs/method.g.dart:38:29)
#9      PreviewCodeGenerator.populatePreviewsInGeneratedPreviewScaffold.<anonymous closure> (package:flutter_tools/src/widget_preview/preview_code_generator.dart:108:14)
#10     _$LibraryBuilder.update (package:code_builder/src/specs/library.g.dart:232:33)
#11     new _$Library (package:code_builder/src/specs/library.g.dart:28:30)
#12     PreviewCodeGenerator.populatePreviewsInGeneratedPreviewScaffold (package:flutter_tools/src/widget_preview/preview_code_generator.dart:104:20)
#13     WidgetPreviewStartCommand.runCommand (package:flutter_tools/src/commands/widget_preview.dart:342:27)
<asynchronous suspension>
#14     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1559:27)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
<asynchronous suspension>
#16     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#17     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:487:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:154:19)
<asynchronous suspension>
�[33m[!]�[39m Flutter (Channel [user-branch], 3.38.3, on macOS 15.7.3 24G419 darwin-arm64, locale en-IN) [1,077ms]
    �[33m!�[39m Flutter version 3.38.3 on channel [user-branch] at /Users/c21866e/flutter_sdk/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
    �[33m!�[39m Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    �[32m•�[39m Framework revision 19074d12f7 (2 months ago), 2025-11-20 17:53:13 -0500
    �[32m•�[39m Engine revision 13e658725d
    �[32m•�[39m Dart version 3.10.1
    �[32m•�[39m DevTools version 2.51.1
    �[32m•�[39m Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging
    �[32m•�[39m If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

�[32m[✓]�[39m Android toolchain - develop for Android devices (Android SDK version 36.1.0) [2.2s]
    �[32m•�[39m Android SDK at /Users/c21866e/Library/Android/sdk
    �[32m•�[39m Emulator version 36.3.10.0 (build_id 14472402) (CL:N/A)
    �[32m•�[39m Platform android-36, build-tools 36.1.0
    �[32m•�[39m ANDROID_HOME = /Users/c21866e/Library/Android/sdk
    �[32m•�[39m Java binary at: /Users/c21866e/Library/Java/JavaVirtualMachines/corretto-17.0.16/Contents/Home/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    �[32m•�[39m Java version OpenJDK Runtime Environment Corretto-17.0.16.8.1 (build 17.0.16+8-LTS)
    �[32m•�[39m All Android licenses accepted.

�[32m[✓]�[39m Xcode - develop for iOS and macOS (Xcode 16.1) [1,996ms]
    �[32m•�[39m Xcode at /Applications/Xcode.app/Contents/Developer
    �[32m•�[39m Build 16B40
    �[32m•�[39m CocoaPods version 1.16.2

�[32m[✓]�[39m Chrome - develop for the web [7ms]
    �[32m•�[39m Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

�[32m[✓]�[39m Connected device (2 available) [7.1s]
    �[32m•�[39m macOS (desktop) • macos  • darwin-arm64   • macOS 15.7.3 24G419 darwin-arm64
    �[32m•�[39m Chrome (web)    • chrome • web-javascript • Google Chrome 144.0.7559.110

�[32m[✓]�[39m Network resources [572ms]
    �[32m•�[39m All expected network resources are available.

�[33m!�[39m Doctor found issues in 1 category.

Flutter Application Metadata

Type: malformed
Version: 0.0.1
Material: true
Android X: false
Module: false
Plugin: false
Android package: null
iOS bundle identifier: null
Creation channel: null
Creation framework version: null

Activity

  1. changed the title [-]Widget-Preview crashes when only MultiPreview annotation is present without a base Preview.[/-] [+]widget-preview crashes when serializing parameterized MultiPreview annotations due to a null constructorInvocation in DartObject.toExpression()[/+] on Jan 31, 2026
  2. added
    in triagePresently being triaged by the triage team
    a: widget previewsIssues related to the Widget Previewer tooling
    team-toolOwned by Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Feb 11, 2026
  3. added
    P1High-priority issues at the top of the work list
    triaged-toolTriaged by Flutter Tool team
    on Feb 23, 2026
  4. bkonyi commented on Feb 23, 2026

    @bkonyi
    Contributor

    Thanks for the report @hemandroid! I can reproduce and will work on getting a fix out soon.

  5. self-assigned this
    on Feb 23, 2026
  6. github-actions commented on Apr 17, 2026

    @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.

  7. locked as resolved and limited conversation to collaborators on Apr 17, 2026
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