to_string_extension 0.4.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

Description #

Uses class_extensions to generate toString for nicely looking text representation of data objects.

See also withers_extension, json_extension

Tutorial #

  1. We need a class to generate toString for.

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

    • part 'model.g.dart';
    • annotation @ToString()
    • mixin _$SomeValueClass
    ${PROJECT_ROOT}/lib/model.dart #
     import 'package:meta/meta.dart';
     import 'package:to_string_extension_annotations/annotations.dart';
    
     part 'model.g.dart';
    
     @ToString()
     @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:
       to_string_extension_annotations: ^0.1.0
    
     dev_dependencies:
       build_runner: ^1.0.0
       to_string_extension: ^0.2.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 print a nice looking text representation of your object.

    ${PROJECT_ROOT}/bin/main.dart #
     import 'package:example/model.dart';
    
     void main() {
       print(SomeValueClass("some", 0).toString()); // prints SomeValueClass(strVal=some, intVal=0)
     }
    
  7. You can also see the example.

0.4.0 #

  • Upgrade dependencies

0.3.0 #

  • Fix generator order

0.2.0 #

  • Upgrade class_extensions dependency

0.1.5 #

  • Refactor

0.1.4 #

  • Update README.md

0.1.3 #

  • Improve README.md

0.1.2 #

  • Fix example link

0.1.1 #

  • Add generated example file

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:
  to_string_extension: ^0.4.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:to_string_extension/to_string_extension.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
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]
69
Learn more about scoring.

We analyzed this package on Jan 19, 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.

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
to_string_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