无法使用flutter设备预览包||没有名称为“nullOk”的命名参数

平台 -

Flutter 1.24.0-10.2.pre • channel dev • https://github.com/flutter/flutter.git
Framework • revision 022b333a08 (8 days ago) • 2020-11-18 11:35:09 -0800
Engine • revision 07c1eed46b
Tools • Dart 2.12.0 (build 2.12.0-29.10.beta)

SRC -

import 'package:flutter/material.dart';

void main() => runApp(
      DevicePreview(
        builder: (context) => MyApp(), // Wrap your app
      ),
    );

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      locale: DevicePreview.locale(context), // Add the locale here
      builder: DevicePreview.appBuilder, // Add the builder here
      home: Text("Home Page"),
    );
  }
}

错误 -

Running "flutter pub get" in xyz...
Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
../../../../../.pub-cache/hosted/pub.dartlang.org/device_preview-0.5.5/lib/src/views/device_preview_style.dart:86:42: Error: No named parameter with the name 'nullOk'.
    final media = MediaQuery.of(context, nullOk: true) ??
                                         ^^^^^^
../../../../../development/flutter/packages/flutter/lib/src/widgets/media_query.dart:814:25: Context: Found this candidate, but the arguments don't match.
  static MediaQueryData of(BuildContext context) {
                        ^^
Failed to compile application.
Exited (sigterm)

在 Pixel 设备上也试过,不起作用。

打开的问题 - https://github.com/aloisdeniel/flutter_device_preview/issues/91

stack overflow Unable to use flutter device preview package || No named parameter with the name 'nullOk'
原文答案

答案:

作者头像

出现此问题的原因是 Flutter 删除了 MediaQuery 中的 nullOk 参数,该参数由 device_preview 插件使用,如本 issue thread 中所述。已推出该插件的更新以解决该问题。