From 64b6379a5b0eafee4af2d3d9fe3b7ff75aa5368e Mon Sep 17 00:00:00 2001 From: Adam Buchweitz Date: Mon, 11 Jul 2022 13:04:27 -0500 Subject: [PATCH] feat: Add freezed support to feature_brick --- bricks/feature_brick/README.md | 1 + .../{{#isBloc}}bloc{{/isBloc}}/bloc.dart | 4 +- .../use_freezed}} | 166 ++++++++++++ .../use_freezed}} | 237 ++++++++++++++++++ .../{{feature_name.snakeCase()}}_bloc.dart | 8 +- .../{{feature_name.snakeCase()}}_event.dart | 11 +- .../{{feature_name.snakeCase()}}_state.dart | 14 +- bricks/feature_brick/hooks/pre_gen.dart | 32 +-- 8 files changed, 450 insertions(+), 23 deletions(-) create mode 100644 bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_event.freezed.dart{{/use_freezed}} create mode 100644 bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_state.dart{{/use_freezed}} diff --git a/bricks/feature_brick/README.md b/bricks/feature_brick/README.md index f35039d..d45f50b 100644 --- a/bricks/feature_brick/README.md +++ b/bricks/feature_brick/README.md @@ -15,6 +15,7 @@ mason make feature_brick --feature_name login --state_management bloc | `feature_name` | The name of the feature | login | `string` | false | N/A | | `state_management` | The state management of the app | bloc | `enum` | false | N/A | | `use_equatable` | Use the equatable package | true | `boolean` | true | Using bloc/cubit | +| `use_freezed` | Use the freezed package | false | `boolean` | true | Using bloc | ## Outputs 📦 diff --git a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/bloc.dart b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/bloc.dart index b398ab6..2cbde1f 100644 --- a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/bloc.dart +++ b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/bloc.dart @@ -1,2 +1,4 @@ export 'package:flutter_bloc/flutter_bloc.dart'; -export '{{feature_name.snakeCase()}}_bloc.dart'; +export '{{feature_name.snakeCase()}}_bloc.dart';{{#use_freezed}} +export '{{feature_name.snakeCase()}}_event.dart'; +export '{{feature_name.snakeCase()}}_state.dart';{{/use_freezed}} diff --git a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_event.freezed.dart{{/use_freezed}} b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_event.freezed.dart{{/use_freezed}} new file mode 100644 index 0000000..a8211d5 --- /dev/null +++ b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_event.freezed.dart{{/use_freezed}} @@ -0,0 +1,166 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of '{{feature_name.snakeCase()}}_event.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _${{feature_name.pascalCase()}}Event { + @optionalTypeArgs + TResult when({ + required TResult Function() event, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function()? event, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? event, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Custom{{feature_name.pascalCase()}}Event value) event, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(Custom{{feature_name.pascalCase()}}Event value)? event, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Custom{{feature_name.pascalCase()}}Event value)? event, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class ${{feature_name.pascalCase()}}EventCopyWith<$Res> { + factory ${{feature_name.pascalCase()}}EventCopyWith( + {{feature_name.pascalCase()}}Event value, $Res Function({{feature_name.pascalCase()}}Event) then) = + _${{feature_name.pascalCase()}}EventCopyWithImpl<$Res>; +} + +/// @nodoc +class _${{feature_name.pascalCase()}}EventCopyWithImpl<$Res> implements ${{feature_name.pascalCase()}}EventCopyWith<$Res> { + _${{feature_name.pascalCase()}}EventCopyWithImpl(this._value, this._then); + + final {{feature_name.pascalCase()}}Event _value; + // ignore: unused_field + final $Res Function({{feature_name.pascalCase()}}Event) _then; +} + +/// @nodoc +abstract class _$$Custom{{feature_name.pascalCase()}}EventCopyWith<$Res> { + factory _$$Custom{{feature_name.pascalCase()}}EventCopyWith(_$Custom{{feature_name.pascalCase()}}Event value, + $Res Function(_$Custom{{feature_name.pascalCase()}}Event) then) = + __$$Custom{{feature_name.pascalCase()}}EventCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$Custom{{feature_name.pascalCase()}}EventCopyWithImpl<$Res> + extends _${{feature_name.pascalCase()}}EventCopyWithImpl<$Res> + implements _$$Custom{{feature_name.pascalCase()}}EventCopyWith<$Res> { + __$$Custom{{feature_name.pascalCase()}}EventCopyWithImpl( + _$Custom{{feature_name.pascalCase()}}Event _value, $Res Function(_$Custom{{feature_name.pascalCase()}}Event) _then) + : super(_value, (v) => _then(v as _$Custom{{feature_name.pascalCase()}}Event)); + + @override + _$Custom{{feature_name.pascalCase()}}Event get _value => super._value as _$Custom{{feature_name.pascalCase()}}Event; +} + +/// @nodoc + +class _$Custom{{feature_name.pascalCase()}}Event implements Custom{{feature_name.pascalCase()}}Event { + const _$Custom{{feature_name.pascalCase()}}Event(); + + @override + String toString() { + return '{{feature_name.pascalCase()}}Event.event()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$Custom{{feature_name.pascalCase()}}Event); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() event, + }) { + return event(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function()? event, + }) { + return event?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? event, + required TResult orElse(), + }) { + if (event != null) { + return event(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Custom{{feature_name.pascalCase()}}Event value) event, + }) { + return event(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function(Custom{{feature_name.pascalCase()}}Event value)? event, + }) { + return event?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Custom{{feature_name.pascalCase()}}Event value)? event, + required TResult orElse(), + }) { + if (event != null) { + return event(this); + } + return orElse(); + } +} + +abstract class Custom{{feature_name.pascalCase()}}Event implements {{feature_name.pascalCase()}}Event { + const factory Custom{{feature_name.pascalCase()}}Event() = _$Custom{{feature_name.pascalCase()}}Event; +} diff --git a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_state.dart{{/use_freezed}} b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_state.dart{{/use_freezed}} new file mode 100644 index 0000000..8a9b951 --- /dev/null +++ b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{#use_freezed}}{{feature_name.snakeCase()}}_state.dart{{/use_freezed}} @@ -0,0 +1,237 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of '{{feature_name.snakeCase()}}_state.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _${{feature_name.pascalCase()}}State { + String get id => throw _privateConstructorUsedError; + int get num => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(String id, int num) initial, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(String id, int num)? initial, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String id, int num)? initial, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function({{feature_name.pascalCase()}}Initial value) initial, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function({{feature_name.pascalCase()}}Initial value)? initial, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function({{feature_name.pascalCase()}}Initial value)? initial, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + ${{feature_name.pascalCase()}}StateCopyWith<{{feature_name.pascalCase()}}State> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class ${{feature_name.pascalCase()}}StateCopyWith<$Res> { + factory ${{feature_name.pascalCase()}}StateCopyWith( + {{feature_name.pascalCase()}}State value, $Res Function({{feature_name.pascalCase()}}State) then) = + _${{feature_name.pascalCase()}}StateCopyWithImpl<$Res>; + $Res call({String id, int num}); +} + +/// @nodoc +class _${{feature_name.pascalCase()}}StateCopyWithImpl<$Res> implements ${{feature_name.pascalCase()}}StateCopyWith<$Res> { + _${{feature_name.pascalCase()}}StateCopyWithImpl(this._value, this._then); + + final {{feature_name.pascalCase()}}State _value; + // ignore: unused_field + final $Res Function({{feature_name.pascalCase()}}State) _then; + + @override + $Res call({ + Object? id = freezed, + Object? num = freezed, + }) { + return _then(_value.copyWith( + id: id == freezed + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + num: num == freezed + ? _value.num + : num // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +abstract class _$${{feature_name.pascalCase()}}InitialCopyWith<$Res> + implements ${{feature_name.pascalCase()}}StateCopyWith<$Res> { + factory _$${{feature_name.pascalCase()}}InitialCopyWith( + _${{feature_name.pascalCase()}}Initial value, $Res Function(_${{feature_name.pascalCase()}}Initial) then) = + __$${{feature_name.pascalCase()}}InitialCopyWithImpl<$Res>; + @override + $Res call({String id, int num}); +} + +/// @nodoc +class __$${{feature_name.pascalCase()}}InitialCopyWithImpl<$Res> + extends _${{feature_name.pascalCase()}}StateCopyWithImpl<$Res> + implements _$${{feature_name.pascalCase()}}InitialCopyWith<$Res> { + __$${{feature_name.pascalCase()}}InitialCopyWithImpl( + _${{feature_name.pascalCase()}}Initial _value, $Res Function(_${{feature_name.pascalCase()}}Initial) _then) + : super(_value, (v) => _then(v as _${{feature_name.pascalCase()}}Initial)); + + @override + _${{feature_name.pascalCase()}}Initial get _value => super._value as _${{feature_name.pascalCase()}}Initial; + + @override + $Res call({ + Object? id = freezed, + Object? num = freezed, + }) { + return _then(_${{feature_name.pascalCase()}}Initial( + id: id == freezed + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + num: num == freezed + ? _value.num + : num // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +class _${{feature_name.pascalCase()}}Initial implements {{feature_name.pascalCase()}}Initial { + const _${{feature_name.pascalCase()}}Initial({required this.id, this.num = 0}); + + @override + final String id; + @override + @JsonKey() + final int num; + + @override + String toString() { + return '{{feature_name.pascalCase()}}State.initial(id: $id, num: $num)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _${{feature_name.pascalCase()}}Initial && + const DeepCollectionEquality().equals(other.id, id) && + const DeepCollectionEquality().equals(other.num, num)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(id), + const DeepCollectionEquality().hash(num)); + + @JsonKey(ignore: true) + @override + _$${{feature_name.pascalCase()}}InitialCopyWith<_${{feature_name.pascalCase()}}Initial> get copyWith => + __$${{feature_name.pascalCase()}}InitialCopyWithImpl<_${{feature_name.pascalCase()}}Initial>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String id, int num) initial, + }) { + return initial(id, num); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult Function(String id, int num)? initial, + }) { + return initial?.call(id, num); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String id, int num)? initial, + required TResult orElse(), + }) { + if (initial != null) { + return initial(id, num); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function({{feature_name.pascalCase()}}Initial value) initial, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult Function({{feature_name.pascalCase()}}Initial value)? initial, + }) { + return initial?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function({{feature_name.pascalCase()}}Initial value)? initial, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class {{feature_name.pascalCase()}}Initial implements {{feature_name.pascalCase()}}State { + const factory {{feature_name.pascalCase()}}Initial({required final String id, final int num}) = + _${{feature_name.pascalCase()}}Initial; + + @override + String get id => throw _privateConstructorUsedError; + @override + int get num => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$${{feature_name.pascalCase()}}InitialCopyWith<_${{feature_name.pascalCase()}}Initial> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_bloc.dart b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_bloc.dart index 020762f..43d4f9a 100644 --- a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_bloc.dart +++ b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_bloc.dart @@ -1,12 +1,12 @@ import 'dart:async'; -import 'package:bloc/bloc.dart';{{#use_equatable}} -import 'package:equatable/equatable.dart';{{/use_equatable}} +{{#use_equatable}}import 'package:equatable/equatable.dart';{{/use_equatable}} +{{#use_freezed}}import 'package:{{packageName}}/{{feature_name.snakeCase()}}/bloc/{{feature_name.snakeCase()}}.dart';{{/use_freezed}}{{^use_freezed}} part '{{feature_name.snakeCase()}}_event.dart'; -part '{{feature_name.snakeCase()}}_state.dart'; +part '{{feature_name.snakeCase()}}_state.dart'; {{/use_freezed}} class {{feature_name.pascalCase()}}Bloc extends Bloc<{{feature_name.pascalCase()}}Event, {{feature_name.pascalCase()}}State> { - {{feature_name.pascalCase()}}Bloc() : super(const {{feature_name.pascalCase()}}Initial()) { + {{feature_name.pascalCase()}}Bloc() : super(const {{feature_name.pascalCase()}}{{^use_freezed}}Initial(){{/use_freezed}}{{#use_freezed}}State.initial(id: ''){{/use_freezed}}) { on(_onCustom{{feature_name.pascalCase()}}Event); } diff --git a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_event.dart b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_event.dart index 648c1e5..78f8108 100644 --- a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_event.dart +++ b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_event.dart @@ -1,4 +1,4 @@ -part of '{{feature_name.snakeCase()}}_bloc.dart'; +{{^use_freezed}}part of '{{feature_name.snakeCase()}}_bloc.dart'; abstract class {{feature_name.pascalCase()}}Event { const {{feature_name.pascalCase()}}Event(); @@ -7,4 +7,11 @@ abstract class {{feature_name.pascalCase()}}Event { /// {@template custom_{{feature_name.snakeCase()}}_event} /// Event added when some custom logic happens /// {@endtemplate} -class Custom{{feature_name.pascalCase()}}Event extends {{feature_name.pascalCase()}}Event {} +class Custom{{feature_name.pascalCase()}}Event extends {{feature_name.pascalCase()}}Event {}{{/use_freezed}}{{#use_freezed}}import 'package:freezed_annotation/freezed_annotation.dart'; + +part '{{feature_name.snakeCase()}}_event.freezed.dart'; + +@freezed +class {{feature_name.pascalCase()}}Event with _${{feature_name.pascalCase()}}Event { + const factory {{feature_name.pascalCase()}}Event.event() = Custom{{feature_name.pascalCase()}}Event; +}{{/use_freezed}} diff --git a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_state.dart b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_state.dart index d94a981..e2dd7c6 100644 --- a/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_state.dart +++ b/bricks/feature_brick/__brick__/{{feature_name.snakeCase()}}/{{#isBloc}}bloc{{/isBloc}}/{{feature_name.snakeCase()}}_state.dart @@ -1,4 +1,4 @@ -part of '{{feature_name.snakeCase()}}_bloc.dart'; +{{^use_freezed}}part of '{{feature_name.snakeCase()}}_bloc.dart'; /// {@template {{feature_name.snakeCase()}}_state} /// {{feature_name.pascalCase()}}State description @@ -31,4 +31,14 @@ class {{feature_name.pascalCase()}}State{{#use_equatable}} extends Equatable{{/u class {{feature_name.pascalCase()}}Initial extends {{feature_name.pascalCase()}}State { /// {@macro {{feature_name.snakeCase()}}_initial} const {{feature_name.pascalCase()}}Initial() : super(); -} +}{{/use_freezed}}{{#use_freezed}}import 'package:freezed_annotation/freezed_annotation.dart'; + +part '{{feature_name.snakeCase()}}_state.freezed.dart'; + +@freezed +class {{feature_name.pascalCase()}}State with _${{feature_name.pascalCase()}}State { + const factory {{feature_name.pascalCase()}}State.initial({ + required String id, + @Default(0) int num, + }) = {{feature_name.pascalCase()}}Initial; +}{{/use_freezed}} diff --git a/bricks/feature_brick/hooks/pre_gen.dart b/bricks/feature_brick/hooks/pre_gen.dart index 8c9c120..87cd0f5 100644 --- a/bricks/feature_brick/hooks/pre_gen.dart +++ b/bricks/feature_brick/hooks/pre_gen.dart @@ -6,21 +6,24 @@ import 'package:yaml/yaml.dart'; Future run(HookContext context) async { final logger = context.logger; - final stateManagement = - context.vars['state_management'].toString().toLowerCase(); + final stateManagement = context.vars['state_management'].toString().toLowerCase(); final isBloc = stateManagement == 'bloc'; final isCubit = stateManagement == 'cubit'; final isProvider = stateManagement == 'provider'; final isRiverpod = stateManagement == 'riverpod'; final isNone = !isBloc && !isCubit && !isProvider && !isRiverpod; - bool useEquatable = false; - if (isBloc || isCubit) { - useEquatable = context.logger.confirm( - '? Do you want to use equatable with your $stateManagement? (Y/n)', - defaultValue: true, - ); - } + final decoratorAnswer = (isBloc || isCubit) + ? logger.chooseOne( + '? Would you like to augment your files?', + choices: [ + 'No thanks', + 'Use Equatable', + if (isBloc) 'Use Freezed', + ], + defaultValue: 'None', + ) + : 'None'; final directory = Directory.current.path; List folders; @@ -32,8 +35,7 @@ Future run(HookContext context) async { } final libIndex = folders.indexWhere((folder) => folder == 'lib'); final featurePath = folders.sublist(libIndex + 1, folders.length).join('/'); - final pubSpecFile = - File('${folders.sublist(0, libIndex).join('/')}/pubspec.yaml'); + final pubSpecFile = File('${folders.sublist(0, libIndex).join('/')}/pubspec.yaml'); final content = await pubSpecFile.readAsString(); final yamlMap = loadYaml(content); final packageName = yamlMap['name']; @@ -44,14 +46,16 @@ Future run(HookContext context) async { context.vars = { ...context.vars, - 'fullPath': ('$packageName/$featurePath/${context.vars['feature_name']}') - .replaceAll('//', '/'), + 'packageName': packageName, + 'fullPath': + ('$packageName/$featurePath/${context.vars['feature_name']}').replaceAll('//', '/'), 'isBloc': isBloc, 'isCubit': isCubit, 'isProvider': isProvider, 'isRiverpod': isRiverpod, 'isNone': isNone, - 'use_equatable': useEquatable + 'use_equatable': decoratorAnswer == 'Use Equatable', + 'use_freezed': decoratorAnswer == 'Use Freezed' }; } on RangeError catch (_) { logger.alert(