defaultTemplate static method

String defaultTemplate({
  1. required bool isNested,
  2. required String constructor,
  3. required String imports,
  4. required String fileName,
  5. required String className,
  6. required String mixinClass,
  7. required String equalsDeclarations,
  8. required String hashDeclarations,
  9. required String declaration,
  10. required String copyWith,
  11. required String cloneFunction,
  12. required String jsonFunctions,
  13. String? enums,
  14. String? enumConverters,
  15. String? nestedClasses,
  16. String? extendsClass,
})

Implementation

static String defaultTemplate({
  required bool isNested,
  required String constructor,
  required String imports,
  required String fileName,
  required String className,
  required String mixinClass,
  required String equalsDeclarations,
  required String hashDeclarations,
  required String declaration,
  required String copyWith,
  required String cloneFunction,
  required String jsonFunctions,
  String? enums,
  String? enumConverters,
  String? nestedClasses,
  String? extendsClass,
}) {
  var template = '';

  if (!isNested) {
    template += '''
import 'package:flutter/foundation.dart';
$imports

''';
  }

  template += '''
@immutable
class $className${extendsClass != null ? ' extends $extendsClass ' : ''}${mixinClass.isNotEmpty ? ' with $mixinClass' : ''} {

$constructor

$declaration

$jsonFunctions

$cloneFunction

''';

  if ((enumConverters?.length ?? 0) > 0) {
    template += '\n$enumConverters';
  }

  template += '''

$copyWith

@override
bool operator ==(Object other) => identical(this, other)
  || other is $className && $equalsDeclarations;

@override
int get hashCode => $hashDeclarations;
''';

  template += '}\n';

  if ((enums?.length ?? 0) > 0) {
    template += '\n$enums\n';
  }

  if ((nestedClasses?.length ?? 0) > 0) {
    template += '\n$nestedClasses';
  }

  return template;
}