ff_annotation_route 1.0.2 ff_annotation_route: ^1.0.2 copied to clipboard
Provide route generator to create route map quickly by annotations.
ff_annotation_route #
Description #
Provide route generator to create route map quickly by annotations.
Usage #
Add packages to dev_dependencies #
add packages to dev_dependencies in your project/packages's pubspec.yaml
dev_dependencies:
ff_annotation_route: any
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
import 'package:ff_annotation_route/ff_annotation_route.dart';
@FFRoute(
name: "fluttercandies://picswiper",
routeName: "PicSwiper",
argumentNames: ["index", "pics"],
showStatusBar: false,
pageRouteType: PageRouteType.transparent)
class PicSwiper extends StatefulWidget {
final int index;
final List<PicSwiperItem> pics;
PicSwiper({this.index, this.pics});
// ...
}
FFRoute
parameter | description | default |
---|---|---|
name | The name of the route (e.g., "/settings"). | required |
argumentNames | The argument names passed to FFRoute. | - |
showStatusBar | Whether show status bar. | true |
routeName | The route name to track page | '' |
pageRouteType | The type of page route(material, cupertino, transparent) | - |
Generate Route File #
Environment
add dart bin into to your $PATH
.
cache\dart-sdk\bin
Activate
pub global activate ff_annotation_route
Execute command
you can cd to your project and exectue command.
ff_annotation_route
or you can exectue command with your project path
ff_annotation_route path=
Command Parameter
use as parameter=xxx, and use space to split them.
parameter | description | default |
---|---|---|
path | The path of your project. | current |
checkEnable | Whether check 'annotation_route_enable' in pubspec.yaml. if true, you should add 'annotation_route_enable: true' into pubspec.yaml if you want to scan files for project/packages | false |
generateRouteNames | Whether generate route names in xxx_route.dart at root project | false |
mode | 0 or 1, 1 will generate xxx_route_helper.dart to help you to handle showStatusBar/routeName/pageRouteType | 0 |
routeSettingsNoArguments | if true, FFRouteSettings(in xxx_route_helper.dart) has no arguments for low flutter sdk | false |
Main.dart #
-
if you exectue command with mode=1, FFNavigatorObserver/FFRouteSettings will generate in xxx_route_helper.dart they help you to track page or change status bar state.
-
if you exectue command with mode=1, FFTransparentPageRoute will generate in xxx_route_helper.dart it helps you to push a transparent page route.
Widget build(BuildContext context) {
return OKToast(
child: MaterialApp(
title: 'ff_annotation_route demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
navigatorObservers: [
FFNavigatorObserver(routeChange: (name) {
//you can track page here
print(name);
}, showStatusBarChange: (bool showStatusBar) {
if (showStatusBar) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
} else {
SystemChrome.setEnabledSystemUIOverlays([]);
}
})
],
builder: (c, w) {
ScreenUtil.instance =
ScreenUtil(width: 750, height: 1334, allowFontScaling: true)
..init(c);
var data = MediaQuery.of(c);
return MediaQuery(
data: data.copyWith(textScaleFactor: 1.0),
child: w,
);
},
initialRoute: "fluttercandies://mainpage",
onGenerateRoute: (RouteSettings settings) {
var routeResult =
getRouteResult(name: settings.name, arguments: settings.arguments);
if (routeResult.showStatusBar != null ||
routeResult.routeName != null) {
settings = FFRouteSettings(
arguments: settings.arguments,
name: settings.name,
isInitialRoute: settings.isInitialRoute,
routeName: routeResult.routeName,
showStatusBar: routeResult.showStatusBar);
}
var page = routeResult.widget ?? NoRoute();
switch (routeResult.pageRouteType) {
case PageRouteType.material:
return MaterialPageRoute(settings: settings, builder: (c) => page);
case PageRouteType.cupertino:
return CupertinoPageRoute(settings: settings, builder: (c) => page);
case PageRouteType.transparent:
return FFTransparentPageRoute(
settings: settings,
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) =>
page);
default:
return Platform.isIOS
? CupertinoPageRoute(settings: settings, builder: (c) => page)
: MaterialPageRoute(settings: settings, builder: (c) => page);
}
},
));
}
Push #
Push name
Navigator.pushNamed(context, "fluttercandies://mainpage");
Push name with arguments
and arguments should be Map<String,dynamic>
Navigator.pushNamed(context, "fluttercandies://picswiper",
arguments: {
"index": index,
"pics": listSourceRepository
.map<PicSwiperItem>(
(f) => PicSwiperItem(f.imageUrl, des: f.title))
.toList(),
});