navarggen 0.1.1

navarggen #

A source code generator for Flutter route navigation arguments.

Getting Started #

Add the packages to your pubspec.yaml file:

dependencies:
  navarggen: ^[latest version]

dev_dependencies:
  build_runner: ^1.5.2 # Also depend on build_runner if you aren't already.
  navarggen_generator: ^[latest version]

Annotate your Widget class with NavigationArguments:

@NavigationArguments({
  'argumentName': ArgumentType,
  'title': String,
  'numbers': 'List<int>', // When you can't pass a Type, you can pass a String. 
})
class YourPage extends StatefulWidget { //...

Specify the part file for the generator code:

part 'your_widget_file_name.g.dart';

Run the build:

$ flutter pub run build_runner build

...or have it watch for changes:

$ flutter pub run build_runner watch

The output will be the following code in the your_widget_file_name.g.dart file:

class YourPageArgs {
  final ArgumentType argumentName;
  final String title;
  final List<int> numbers;
  
  YourPageArgs({this.argumentName, this.title, this.numbers});
}

You can then use it to pass arguments to your route like usual:

Navigator.of(context).pushNamed(
  Routes.YOUR_PAGE,
  arguments: YourPageArgs({
    argumentName: someObject,
    title: 'Your Title',
    numbers: [0, 1, 2, 3, 4],
  }),
);

Then in YourPage:

YourPageArgs args = ModalRoute.of(context).settings.arguments;

See the example project for a working example.

Use this package as a library

1. Depend on it

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


dependencies:
  navarggen: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


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

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

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:navarggen/navarggen.dart.

Health issues and suggestions

Document public APIs. (-1 points)

4 out of 4 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/navarggen.dart.

Run dartfmt to format lib/navarggen.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and navarggen.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0