|
|
@@ -7,7 +7,7 @@ import 'package:router_gen/util/utils.dart';
|
|
|
import 'package:source_gen/source_gen.dart';
|
|
|
import 'package:path/path.dart' as Path;
|
|
|
|
|
|
-/// save router annotation to router
|
|
|
+/// save router annotation
|
|
|
class RouterGenerator extends GeneratorForAnnotation<RouterPage> {
|
|
|
final _paramChecker = const TypeChecker.fromRuntime(RouterParam);
|
|
|
|
|
|
@@ -22,14 +22,16 @@ class RouterGenerator extends GeneratorForAnnotation<RouterPage> {
|
|
|
|
|
|
// router name
|
|
|
String className = element.name;
|
|
|
- String aptName = annotation.peek("path")?.stringValue;
|
|
|
+ String aptPath = annotation.peek("path")?.stringValue;
|
|
|
String routerName =
|
|
|
- toCamelCase(aptName == null || aptName.isEmpty ? className : aptName);
|
|
|
+ toCamelCase(aptPath == null || aptPath.isEmpty ? className : aptPath);
|
|
|
|
|
|
var page = Page();
|
|
|
page.name = className;
|
|
|
- page.path = Path.join(
|
|
|
- path.replaceFirst("lib", "").replaceFirst(basename, ""), routerName);
|
|
|
+ page.path = routerName.startsWith("/")
|
|
|
+ ? routerName
|
|
|
+ : Path.join(path.replaceFirst("lib", "").replaceFirst(basename, ""),
|
|
|
+ routerName);
|
|
|
page.arguments = [];
|
|
|
|
|
|
for (FieldElement e in (element as ClassElement).fields) {
|
|
|
@@ -44,8 +46,8 @@ class RouterGenerator extends GeneratorForAnnotation<RouterPage> {
|
|
|
));
|
|
|
}
|
|
|
}
|
|
|
- router.routerMap[routerName] = page;
|
|
|
+ router.routerMap[Path.basename(routerName)] = page;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
-}
|
|
|
+}
|