Skip to content

Commit

Permalink
Merge pull request #14 from iota9star/issue-6
Browse files Browse the repository at this point in the history
fixed #6.
  • Loading branch information
zmtzawqlp committed Feb 14, 2020
2 parents fd72892 + 6202c0a commit 673df84
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions lib/src/route_generator.dart
Expand Up @@ -84,28 +84,53 @@ class RouteGenerator {

for (final item in parameters) {
if (item is NamedExpressionImpl) {
var source = item.expression.toSource();
if (source == 'null') continue;
// using single quotes has greater possibility.
if (source.length >= 2 &&
source.startsWith("'") &&
source.endsWith("'")) {
source = '"${source.substring(1, source.length - 1)}"';
} else if (source.startsWith("'''") &&
source.endsWith("'''")) {
source = '"${source.substring(3, source.length - 3)}"';
}
final key = item.name.toSource();
if (key == 'name:') {
name = item.expression.toSource();
} else if (key == 'argumentNames:') {
final list = json.decode(
item.expression.toSource(),
) as List;
argumentNames = list.map((f) => f.toString()).toList();
} else if (key == 'showStatusBar:') {
showStatusBar = item.expression.toSource() == 'true';
} else if (key == 'routeName:') {
routeName = item.expression.toSource();
} else if (key == 'pageRouteType:') {
pageRouteType = PageRouteType.values.firstWhere(
(type) => type.toString() == item.expression.toSource(),
orElse: () => null,
);
} else if (key == 'description:') {
description = item.expression.toSource();
switch (key) {
case 'name:':
name = source;
break;
case 'routeName:':
routeName = source;
break;
case 'showStatusBar:':
showStatusBar = source == 'true';
break;
case 'argumentNames:':
argumentNames = source
.replaceAll(RegExp('\\[|\\]'), '')
.split(',')
.map((it) => it.trim())
.where((it) => it.length > 2)
.map((it) =>
it.startsWith("'''") && it.endsWith("'''")
? it.substring(3, it.length - 3)
: it.substring(1, it.length - 1))
.toList();
break;
case 'pageRouteType:':
pageRouteType = PageRouteType.values.firstWhere(
(type) => type.toString() == source,
orElse: () => null,
);
break;
case 'description:':
description = source;
break;
}
}
}

final routeInfo = RouteInfo(
className: className,
ffRoute: FFRoute(
Expand Down

0 comments on commit 673df84

Please sign in to comment.