Skip to content

Dummies

Efra Espada edited this page Oct 6, 2024 · 6 revisions

What are dummies?

Dummies are dart classes that provide the dummy content of your sample (or samples). For working with dummies, @Preview annotations require an extra configuration.

your_widget_folder
    |
    |-- preview
    |   |
    |   |-- dummy
    |   |   |
    |   |   |-- gs_image.dummy.dart      <-- dummy created (only created if not exist)
    |   |
    |   |-- gs_image.preview.dart        <-- preview created (always regenerated)
    |
    |--gs_image.dart                     <-- widget file

Notice the suffix preview is defined in pubspec.yaml

Prepare dummies

dart run catalog:preview

After running the preview command, a dummy file is generated if it does not exist.

gs_image.dummy.dart

/// AUTOGENERATED FILE.
///
/// Use this file for modify the preview of GsImagePreview
///

import 'package:catalog/catalog.dart';

class GsImageDummy extends PreviewDummy {
  @override
  List<Dummy> get dummies => [];
}

Every Dummy element you include in the dummies variable is displayed as a different sample of your widget preview.

gs_image.dummy.dart

/// AUTOGENERATED FILE.
///
/// Use this file for modify the preview of GsImagePreview
///

import 'package:catalog/catalog.dart';
import 'package:landa/data/model/profile.dart';

class GsImageDummy extends PreviewDummy {
  @override
  List<Dummy> get dummies => [
        Dummy(
          parameters: {
            'profile': Profile().fromJson(
              {
                'id': '1107d2a893dd295e57f',
                'name': 'Efra Espada',
                'username': 'efraespada',
              },
            ),
            'size': 150,
            'height': 150,
            'width': 150.0,
            'elevation': 2.0,
          },
        ),
      ];
}

Clone this wiki locally