barrel_files 0.1.1 barrel_files: ^0.1.1 copied to clipboard
Generate barrel files for Dart and Flutter packages with build_runner based on code annotations
- Add dependency:
# pubspec.yaml
name: example_package
dependencies:
barrel_files_annotation:
...
dev_dependencies:
barrel_files:
build_runner:
...
- Annotate public top elements:
// lib/src/example_input.dart
import 'package:barrel_files_annotation/barrel_files_annotation.dart';
@includeInBarrelFile
class ExampleClass {}
@includeInBarrelFile
const exampleGlobalConst = 0;
@includeInBarrelFile
enum ExampleEnum {one, two, three}
@includeInBarrelFile
String exampleFunction() => 'example';
@includeInBarrelFile
typedef ExampleTypeDef = void Function(int i);
- Run code generation:
dart run build_runner build --delete-conflicting-outputs
- Have the barrel file generated:
// lib/example_package.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
export 'package:example_package/src/example_input.dart'
show
ExampleClass,
ExampleEnum,
ExampleTypeDef,
exampleFunction,
exampleGlobalConst;