field_mappers_extension 0.3.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Description #

Uses class_extensions to generate field mappers. Field mappers are a convenient way of constructing copies of immutable objects with altered values.

See also to_string_extension, json_extension, withers_extension

Tutorial #

  1. We need a class to generate field mappers for. You usually want to generate field mappers for immutable classes.

    ${PROJECT_ROOT}/lib/model.dart
     import 'package:meta/meta.dart';
    
     @immutable
     class SomeValueClass {
       final String strVal;
       final int intVal;
     }
    
  2. For field mappers to work you need to add some boiler plate:

    • part 'model.g.dart';
    • annotation @FieldMappers()
    • mixin _$SomeValueClass
    • all args constructor SomeValueClass(this.strVal, this.intVal);
    ${PROJECT_ROOT}/lib/model.dart
     import 'package:meta/meta.dart';
     import 'package:field_mappers_extension_annotations/annotations.dart';
    
     part 'model.g.dart';
    
     @FieldMappers()
     @immutable
     class SomeValueClass with _$SomeValueClass {
       final String strVal;
       final int intVal;
    
       SomeValueClass(this.strVal, this.intVal);
     }
    
  3. Configure code generation. More info at build.

    ${PROJECT_ROOT}/build.yaml
     targets:
       $default:
         builders:
           class_extensions:
             generate_for:
             - lib/*.dart
    
  4. Add dependencies.

    ${PROJECT_ROOT}/pubspec.yaml
     name: example
    
     dependencies:
       field_mappers_extension_annotations: ^0.1.0
    
     dev_dependencies:
       build_runner: ^1.0.0
       field_mappers_extension: 8.0.0
    
  5. Run code generation: pub run build_runner build. File ${PROJECT_ROOT}/lib/model.g.dart should be created.

  6. If everything goes well you should be able to use field mappers.

    ${PROJECT_ROOT}/bin/main.dart
     import 'package:example/model.dart';
    
     void main() {
       var some = SomeValueClass("some", 0);
       var other = some.mapIntVal((old) => old + 1).mapStrVal((old) => old + " other");
       print('${other.strVal} ${other.intVal}');
     }
    
  7. You can also see the example.

0.3.1 #

  • Fix CHANGELOG.md

0.3.0 #

  • Generate only for fields in ctor

0.2.0 #

  • Fix generics

0.1.0 #

  • Initialize package

example/README.md

Description #

The tutorial example.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  field_mappers_extension: ^0.3.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:field_mappers_extension/field_mappers_extension.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/type_checker.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:field_mappers_extension/field_mappers_extension.dartpackage:field_mappers_extension/src/field_mappers_generator.dartpackage:source_gen/source_gen.dartpackage:source_gen/src/utils.dartpackage:build/build.dartpackage:build/src/generate/run_post_process_builder.dartpackage:build/src/builder/post_process_builder.dartpackage:build/src/builder/builder.dartpackage:build/src/builder/build_step.dartpackage:build/src/asset/reader.dartpackage:glob/glob.dartpackage:glob/src/list_tree.dartpackage:glob/src/io.dartpackage:glob/src/io_export.dartdart:io

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/field_mappers_extension.dart.

Run dartfmt to format lib/field_mappers_extension.dart.

Format lib/src/field_mappers_generator.dart.

Run dartfmt to format lib/src/field_mappers_generator.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
analyzer ^0.39.0 0.39.12
build >=0.12.6 <2.0.0 1.3.0
class_extensions ^0.10.0 0.10.2
field_mappers_extension_annotations ^0.1.0 0.1.0
source_gen ^0.9.0 0.9.5
Transitive dependencies
_fe_analyzer_shared 5.0.0
args 1.6.0
async 2.4.2
charcode 1.1.3
class_extensions_annotations 0.2.0
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
glob 1.2.0
html 0.14.0+3
js 0.6.2
logging 0.11.4
meta 1.2.2 1.3.0-nullsafety
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
path 1.7.0
pedantic 1.9.2
pub_semver 1.4.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
watcher 0.9.7+15
yaml 2.2.1
Dev dependencies
build_runner ^1.0.0