Skip to main content

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');