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');
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.