withers_extension 0.8.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

Description #

Uses class_extensions to generate withers. Withers are a convenient way of constructing copies of immutable objects with altered values.

See also to_string_extension, json_extension

Tutorial #

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

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

    • part 'model.g.dart';
    • annotation @Withers()
    • mixin _$SomeValueClass
    • all args constructor SomeValueClass(this.strVal, this.intVal);
    ${PROJECT_ROOT}/lib/model.dart #
     import 'package:meta/meta.dart';
     import 'package:withers_extension_annotations/annotations.dart';
    
     part 'model.g.dart';
    
     @Withers()
     @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:
       withers_extension_annotations: ^0.1.0
    
     dev_dependencies:
       build_runner: ^1.0.0
       withers_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 withers.

    ${PROJECT_ROOT}/bin/main.dart #
     import 'package:example/model.dart';
    
     void main() {
       var some = SomeValueClass("some", 0);
       var other = some.withIntVal(1).withStrVal("other");
     }
    
  7. You can also see the example.

0.8.0 #

  • Upgrade dependencies

0.7.0 #

  • Fix build configuration
  • Upgrade class_extensions dependency

0.6.0 #

  • Upgrade class_extensions dependency

0.5.3 #

  • Update README.md

0.5.2 #

  • Improve README.md

0.5.1 #

  • Fix example link

0.5.0 #

  • Upgrade dependencies

0.4.2 #

  • Update README.md

0.4.1 #

  • Update example

0.4.0 #

  • Upgrade class_extensions dependency

0.3.0 #

  • Extract annotations to separate package

0.2.0 #

  • Make internal generator methods private

0.1.2 #

  • Update README.md
  • Add example README.md

0.1.1 #

  • Fix homepage

0.1.0 #

  • Add example

0.0.2 #

  • Improve package description

0.0.1 #

  • Add CHANGELOG.md
  • Improve README.md
  • Refactor code

0.0.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:
  withers_extension: ^0.8.0

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:withers_extension/withers_extension.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
29
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]
64
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4

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.

Fix lib/src/withers_generator.dart. (-0.50 points)

Analysis of lib/src/withers_generator.dart reported 1 hint:

line 20 col 54: 'name' is deprecated and shouldn't be used. Check element, or use getDisplayString().

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
analyzer ^0.39.0 0.39.4
build >=0.12.6 <2.0.0 1.2.2
class_extensions ^0.10.0 0.10.2
source_gen ^0.9.0 0.9.4+7
withers_extension_annotations ^0.2.0 0.2.0
Transitive dependencies
_fe_analyzer_shared 1.0.3
args 1.5.2
async 2.4.0
charcode 1.1.2
class_extensions_annotations 0.2.0
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
logging 0.11.4
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.2
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
build_runner ^1.0.0