smf_contracts 0.3.0 copy "smf_contracts: ^0.3.0" to clipboard
smf_contracts: ^0.3.0 copied to clipboard

The module model of Say My Frame, the Flutter app generator. Modules declare roles, such as a router, and contribute templates, code for sockets and checks.

example/smf_contracts_example.dart

// A module of your own on the module model: it sets up the logging package
// in the Flutter apps that SMF generates.
//
// The module adds the package to the dependencies of the app, puts a line
// into the early phase of `bootstrap()` that prints the log records (INFO
// and above by default), and adds a section to the README of the app. It
// names no other module, so it fits any app.
//
// To offer it in `smf create`, pass it to `runCli` of smf_flutter_cli
// together with the modules of SMF. The example of smf_pipeline tests it
// with the contract harness. See https://doc.saymyframe.com/extending.
import 'package:smf_contracts/smf_contracts.dart';

/// Sets up the logging package in the app.
final class LoggingModule extends SmfModule {
  /// Creates the module.
  const LoggingModule();

  /// The id of the module, which `smf create -m logging` takes.
  static const id = ModuleId('logging');

  @override
  ModuleDescriptor get descriptor => const ModuleDescriptor(
        id: id,
        description: 'Logging with the logging package',
        kind: ModuleKinds.infrastructure,
      );

  @override
  List<Contribution> contribute(ModuleContext context) => [
        const PubspecContribution.hosted('logging', '^1.3.0'),
        const SocketContribution.code(
          AppEntryRole.bootstrapEarly,
          Fragment(
            'Logger.root.onRecord.listen((record) => '
            r"debugPrint('${record.level.name}: ${record.message}'));",
            imports: [
              ImportRef(
                'package:flutter/foundation.dart',
                show: ['debugPrint'],
              ),
              ImportRef('package:logging/logging.dart', show: ['Logger']),
            ],
          ),
        ),
        AppEntryRole.readmeSections.entry(
          'Logging',
          'The app logs with the [logging](https://pub.dev/packages/logging) '
              'package: create a `Logger` for each class. `bootstrap()` '
              'prints the records at `Logger.root.level` and above, which is '
              'INFO by default.',
        ),
      ];
}
0
likes
160
points
14
downloads

Documentation

Documentation
API reference

Publisher

verified publishersaymyframe.com

Weekly Downloads

The module model of Say My Frame, the Flutter app generator. Modules declare roles, such as a router, and contribute templates, code for sockets and checks.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#flutter #code-generation #modules #template

License

Apache-2.0 (license)

Dependencies

mason, meta

More

Packages that depend on smf_contracts