invalid_widget_preview_private_argument
'@Preview(...)' can only accept arguments that consist of literals and public symbols.
Description
#The analyzer produces this diagnostic when the Preview
constructor is
invoked with arguments that contain references to private symbols.
Example
#The following code produces this diagnostic because the constant variable
_name
is private to the current library:
dart
import 'package:flutter/widgets.dart';
import 'package:flutter/widget_previews.dart';
const String _name = 'My Foo Preview';
@Preview(name: _name)
Widget myPreview() => Text('Foo');
Common fixes
#If appropriate, the private symbol should be made public:
dart
import 'package:flutter/widgets.dart';
import 'package:flutter/widget_previews.dart';
const String name = 'My Foo Preview';
@Preview(name: name)
Widget myPreview() => Text('Foo');
Otherwise, a different public constant symbol should be used:
dart
import 'package:flutter/widgets.dart';
import 'package:flutter/widget_previews.dart';
@Preview(name: 'My Foo Preview')
Widget myPreview() => Text('Foo');
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。