ff_annotation_route 4.0.0 copy "ff_annotation_route: ^4.0.0" to clipboard
ff_annotation_route: ^4.0.0 copied to clipboard

outdated

Provide a route generator to create route map quickly by annotations.

ff_annotation_route #

pub package GitHub stars GitHub forks GitHub license GitHub issues flutter-candies

Languages: English | 中文简体

Description #

Provide a route generator to create route map quickly by annotations.

Usage #

Add packages to dev_dependencies #

Add the package to dev_dependencies in your project/packages's pubspec.yaml

dev_dependencies:
  ff_annotation_route: latest-version

Download with flutter packages get

Add annotation #

Empty Constructor

import 'package:ff_annotation_route/ff_annotation_route.dart';

@FFRoute(
  name: "fluttercandies://mainpage",
  routeName: "MainPage",
)
class MainPage extends StatelessWidget
{
  // ...
}

Constructor with arguments

The tool will handle it. What you should take care is that provide import url by setting argumentImports if it has class/enum argument.

import 'package:ff_annotation_route/ff_annotation_route.dart';

@FFRoute(
  name: 'flutterCandies://testPageE',
  routeName: 'testPageE',
  description: 'This is test page E.',
  argumentImports: <String>[
    'import \'package:example/src/model/test_model.dart\';',
    'import \'package:example/src/model/test_model1.dart\';'
  ],
  exts: <String, dynamic>{
    'group': 'Complex',
    'order': 1,
  },
)
class TestPageE extends StatelessWidget {
  const TestPageE({
    this.testMode = const TestMode(
      id: 2,
      isTest: false,
    ),
    this.testMode1,
  });
  factory TestPageE.deafult() => TestPageE(
        testMode: TestMode.deafult(),
      );

  factory TestPageE.required({@required TestMode testMode}) => TestPageE(
        testMode: testMode,
      );

  final TestMode testMode;
  final TestMode1 testMode1;
}

FFRoute

Parameter Description Default
name The name of the route (e.g., "/settings") required
showStatusBar Whether to show the status bar. true
routeName The route name to track page. ''
pageRouteType The type of page route.(material, cupertino, transparent) -
description The description of the route. ''
exts The extend arguments. -
argumentImports The imports of arguments. For example, class/enum argument should provide import url. -

Generate Route File #

Environment

Add dart bin into to your $PATH.

cache\dart-sdk\bin

More info

Activate the plugin

pub global activate ff_annotation_route

Execute command

Go to your project's root and execute command.

ff_route <command> [arguments]

Command Parameter

Available commands:

command name description
-h, --help Print this usage information.
-p, --path [arguments] The path of folder to be executed with commands.
-rc, --route-constants Whether generate route names as constants.
-rh, --route-helper Whether generate xxx_route_helper.dart
-rn, --route-names Whether generate route names as a list.
-s, --save Whether save commands in local, it will read commands from local next time to execute if run "ff_route" without any commands.
-na, --no-arguments Whether RouteSettings has arguments(for lower flutter sdk).
-g, --git package1,package2 Whether scan git lib,you should specify package names and split multiple by ','.
--package Is this a package.
--no-is-initial-route Whether RouteSettings has isInitialRoute(for higher flutter sdk).
-o --output The path of main project route file and helper file. it is relative to the lib directory.
-rfo --routes-file-output The path of routes file.It is relative to the lib directory.

Main.dart #

  • If you execute command with --route-helper, FFNavigatorObserver/FFRouteSettings will generate in xxx_route_helper.dart which help you to track page or change status bar state.

  • If you execute command with --route-helper, FFTransparentPageRoute will generate in xxx_route_helper.dart which helps you to push a transparent page route.

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ff_annotation_route demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      initialRoute: Routes.fluttercandiesMainpage,
      onGenerateRoute: (RouteSettings settings) {
        //when refresh web, route will as following
        //   /
        //   /fluttercandies:
        //   /fluttercandies:/
        //   /fluttercandies://mainpage
        if (kIsWeb && settings.name.startsWith('/')) {
          return onGenerateRouteHelper(
            settings.copyWith(name: settings.name.replaceFirst('/', '')),
            notFoundFallback:
                getRouteResult(name: Routes.fluttercandiesMainpage).widget,
          );
        }
        return onGenerateRouteHelper(settings,
            builder: (Widget child, RouteResult result) {
          if (settings.name == Routes.fluttercandiesMainpage ||
              settings.name == Routes.fluttercandiesDemogrouppage) {
            return child;
          }
          return CommonWidget(
            child: child,
            result: result,
          );
        });
      },
    );
  }
}

Push #

Push name

  Navigator.pushNamed(context, Routes.fluttercandiesMainpage /* fluttercandies://mainpage */);

Push name with arguments

arguments MUST be a Map<String, dynamic>

  Navigator.pushNamed(
    context,
    Routes.flutterCandiesTestPageE,
    arguments: <String, dynamic>{
      constructorName: 'required',
      'testMode': const TestMode(
        id: 100,
        isTest: true,
      ),
    },
  );

Code Hints

you can use route as 'Routes.flutterCandiesTestPageE', and see Code Hints from ide.

  /// 'This is test page E.'
  ///
  /// [name] : 'flutterCandies://testPageE'
  ///
  /// [routeName] : 'testPageE'
  ///
  /// [description] : 'This is test page E.'
  ///
  /// [constructors] :
  ///
  /// TestPageE : [TestMode testMode, TestMode1 testMode1]
  ///
  /// TestPageE.deafult : []
  ///
  /// TestPageE.required : [TestMode(required) testMode]
  ///
  /// [exts] : {group: Complex, order: 1}
  static const String flutterCandiesTestPageE = 'flutterCandies://testPageE';
13
likes
0
pub points
54%
popularity

Publisher

verified publisherfluttercandies.com

Provide a route generator to create route map quickly by annotations.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, dart_style, io, meta, path, yaml

More

Packages that depend on ff_annotation_route