Line data Source code
1 : import 'dart:convert';
2 :
3 : import 'package:flutter_navigation_generator/src/models/importable_type.dart';
4 : import 'package:flutter_navigation_generator_annotations/flutter_navigation_generator_annotations.dart';
5 :
6 : class RouteConfig {
7 : final bool isFullscreenDialog;
8 : final bool generatePageRoute;
9 : final bool generateMethod;
10 : final bool routeNameIsDefinedByAnnotation;
11 : final bool methodNameIsDefinedByAnnotation;
12 : final String routeName;
13 : final String methodName;
14 : final String constructorName;
15 : final ImportableType routeWidget;
16 : final ImportableType? returnType;
17 : final ImportableType? pageType;
18 : final NavigationType navigationType;
19 : final List<ImportableType> parameters;
20 : final List<ImportableType>? guards;
21 : final Map<String, dynamic> defaultValues;
22 :
23 3 : bool get routeNameContainsParameters => routeName.contains(':');
24 :
25 2 : RouteConfig({
26 : required this.routeWidget,
27 : this.routeName = '',
28 : this.methodName = '',
29 : this.constructorName = '',
30 : this.pageType,
31 : this.isFullscreenDialog = false,
32 : this.generatePageRoute = true,
33 : this.generateMethod = true,
34 : this.routeNameIsDefinedByAnnotation = false,
35 : this.methodNameIsDefinedByAnnotation = false,
36 : this.returnType,
37 : this.navigationType = NavigationType.push,
38 : this.parameters = const [],
39 : this.guards,
40 : this.defaultValues = const {},
41 : });
42 :
43 0 : Map<String, dynamic> toMap() {
44 0 : return {
45 0 : 'isFullscreenDialog': isFullscreenDialog,
46 0 : 'generatePageRoute': generatePageRoute,
47 0 : 'generateMethod': generateMethod,
48 0 : 'constructorName': constructorName,
49 0 : 'routeName': routeName,
50 0 : 'methodName': methodName,
51 0 : 'routeNameIsDefinedByAnnotation': routeNameIsDefinedByAnnotation,
52 0 : 'methodNameIsDefinedByAnnotation': methodNameIsDefinedByAnnotation,
53 0 : 'returnType': returnType?.toMap(),
54 0 : 'pageType': pageType?.toMap(),
55 0 : 'routeWidget': routeWidget.toMap(),
56 0 : 'navigationType': navigationType.index,
57 0 : 'parameters': parameters.map((x) => x.toMap()).toList(),
58 0 : 'guards': guards?.map((x) => x.toMap()).toList(),
59 0 : 'defaultValues': defaultValues,
60 : };
61 : }
62 :
63 0 : factory RouteConfig.fromMap(Map<String, dynamic> map) {
64 0 : return RouteConfig(
65 0 : isFullscreenDialog: map['isFullscreenDialog'] ?? false,
66 0 : generatePageRoute: map['generatePageRoute'] ?? false,
67 0 : generateMethod: map['generateMethod'] ?? false,
68 0 : constructorName: map['constructorName'] ?? '',
69 0 : routeName: map['routeName'] ?? '',
70 0 : methodName: map['methodName'] ?? '',
71 : routeNameIsDefinedByAnnotation:
72 0 : map['routeNameIsDefinedByAnnotation'] ?? '',
73 : methodNameIsDefinedByAnnotation:
74 0 : map['methodNameIsDefinedByAnnotation'] ?? '',
75 0 : routeWidget: ImportableType.fromMap(map['routeWidget']),
76 0 : returnType: map['returnType'] != null
77 0 : ? ImportableType.fromMap(map['returnType'])
78 : : null,
79 0 : pageType: map['pageType'] != null
80 0 : ? ImportableType.fromMap(map['pageType'])
81 : : null,
82 0 : navigationType: NavigationType.values[map['navigationType']],
83 0 : parameters: List<ImportableType>.from(map['parameters']?.map(
84 0 : (dynamic x) => ImportableType.fromMap(x as Map<String, dynamic>))
85 : as Iterable),
86 0 : guards: map['guards'] == null
87 : ? null
88 0 : : List<ImportableType>.from(map['guards'].map((dynamic x) =>
89 0 : ImportableType.fromMap(x as Map<String, dynamic>)) as Iterable),
90 : defaultValues:
91 0 : map['defaultValues'] as Map<String, dynamic>? ?? <String, dynamic>{},
92 : );
93 : }
94 :
95 0 : String toJson() => json.encode(toMap());
96 :
97 0 : factory RouteConfig.fromJson(String source) =>
98 0 : RouteConfig.fromMap(json.decode(source));
99 : }
|