Skip to content

Commit cd98507

Browse files
committed
+breaking: Make improvements to generated output
1 parent d85b503 commit cd98507

12 files changed

+446
-31
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@
1717
**/.github/.git
1818
**/.metadata
1919
**/.flutter-plugins
20-
**/.flutter-plugins-dependencies
20+
**/.flutter-plugins-dependencies
21+
**/pubspec_overrides.yaml
22+
23+
# Don't support IntelliJ.
24+
**/*.iml
25+
**/*.idea/

lib/src/_generator_converger.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ final generatorConverger = _GeneratorConverger(
2626
final [
2727
controllerTemplate,
2828
screenTemplate,
29-
viewTemplate,
29+
stateTemplate,
3030
] = templates;
3131

3232
for (final replacement in replacements) {
3333
final templates = {
3434
replacement.insight.controllerFileName: controllerTemplate,
3535
replacement.insight.screenFileName: screenTemplate,
36-
replacement.insight.viewFileName: viewTemplate,
36+
replacement.insight.stateFileName: stateTemplate,
3737
};
3838
for (final entry in templates.entries) {
3939
final fileName = entry.key;

lib/src/generate_screen/_generator_converger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final generatorConverger = _GeneratorConverger(
3333
final templates = {
3434
replacement.insight.controllerFileName: controllerTemplate,
3535
replacement.insight.screenFileName: screenTemplate,
36-
replacement.insight.viewFileName: viewTemplate,
36+
replacement.insight.stateFileName: viewTemplate,
3737
};
3838
for (final entry in templates.entries) {
3939
final fileName = entry.key;

lib/src/generate_screen/_insight.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Insight {
1515
final String bindingsFileName;
1616
final String controllerFileName;
1717
final String screenFileName;
18-
final String viewFileName;
18+
final String stateFileName;
1919
final bool isAccessibleOnlyIfLoggedIn;
2020
final bool isAccessibleOnlyIfLoggedInAndVerified;
2121
final bool isAccessibleOnlyIfLoggedOut;
@@ -31,7 +31,7 @@ class Insight {
3131
required this.bindingsFileName,
3232
required this.controllerFileName,
3333
required this.screenFileName,
34-
required this.viewFileName,
34+
required this.stateFileName,
3535
required this.isAccessibleOnlyIfLoggedIn,
3636
required this.isAccessibleOnlyIfLoggedInAndVerified,
3737
required this.isAccessibleOnlyIfLoggedOut,

lib/src/generate_screen/_insight_mappers.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ final insightMappers = [
4747
},
4848
),
4949
_InsightMapper(
50-
placeholder: Placeholders.VIEW_FILE,
50+
placeholder: Placeholders.STATE_FILE,
5151
mapInsights: (insight) async {
52-
return insight.viewFileName;
52+
return insight.stateFileName;
5353
},
5454
),
5555
_InsightMapper(
@@ -66,9 +66,7 @@ final insightMappers = [
6666
_InsightMapper(
6767
placeholder: Placeholders.I1,
6868
mapInsights: (insight) async {
69-
final q1 = insight.queryParameters
70-
.map((e) => 'late final $e = configuration.$e;')
71-
.join('\n');
69+
final q1 = insight.queryParameters.map((e) => 'late final $e = configuration.$e;').join('\n');
7270
return q1;
7371
},
7472
),
@@ -92,17 +90,13 @@ final insightMappers = [
9290
final generateScreenBindingsArgs = [
9391
if (insight.path != null) "path: '${insight.path}'",
9492
if (insight.title != null) "title: '${insight.title}'",
95-
if (insight.isAccessibleOnlyIfLoggedIn)
96-
'isAccessibleOnlyIfLoggedIn: true',
93+
if (insight.isAccessibleOnlyIfLoggedIn) 'isAccessibleOnlyIfLoggedIn: true',
9794
if (insight.isAccessibleOnlyIfLoggedInAndVerified)
9895
'isAccessibleOnlyIfLoggedInAndVerified: true',
99-
if (insight.isAccessibleOnlyIfLoggedOut)
100-
'isAccessibleOnlyIfLoggedOut: true',
96+
if (insight.isAccessibleOnlyIfLoggedOut) 'isAccessibleOnlyIfLoggedOut: true',
10197
if (insight.isRedirectable) 'isRedirectable: true',
102-
if (insight.internalParameters.isNotEmpty && a.isNotEmpty)
103-
'internalParameters: {$a,}',
104-
if (insight.queryParameters.isNotEmpty && b.isNotEmpty)
105-
'queryParameters: {$b,}',
98+
if (insight.internalParameters.isNotEmpty && a.isNotEmpty) 'internalParameters: {$a,}',
99+
if (insight.queryParameters.isNotEmpty && b.isNotEmpty) 'queryParameters: {$b,}',
106100
].join(',');
107101
return generateScreenBindingsArgs;
108102
},
@@ -125,7 +119,7 @@ enum Placeholders {
125119
BINDINGS_FILE,
126120
CONTROLLER_FILE,
127121
SCREEN_FILE,
128-
VIEW_FILE,
122+
STATE_FILE,
129123
Q1,
130124
I1,
131125
GENERATE_SCREEN_BINDINGS_ARGS,

lib/src/generate_screen/generate.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,19 @@ Future<void> generateScreen({
5050
))!,
5151
);
5252

53-
final viewTemplate = extractCodeFromMarkdown(
53+
final stateTemplate = extractCodeFromMarkdown(
5454
(await FileSystemUtility.i
55-
.readFileFromPathOrUrl([templatePathOrUrl, 'view.dart.md'].join('/')))!,
55+
.readFileFromPathOrUrl([templatePathOrUrl, 'state.dart.md'].join('/')))!,
5656
);
5757

5858
final insight = Insight(
5959
screenClassName: screenName.toPascalCase(),
6060
bindingsFileName: '_bindings.g.dart',
6161
controllerFileName: '_controller.dart',
6262
screenFileName: '${screenName.toSnakeCase()}.dart',
63-
viewFileName: '_view.dart',
63+
stateFileName: '_state.dart',
6464
isAccessibleOnlyIfLoggedIn: isAccessibleOnlyIfLoggedIn,
65-
isAccessibleOnlyIfLoggedInAndVerified:
66-
isAccessibleOnlyIfLoggedInAndVerified,
65+
isAccessibleOnlyIfLoggedInAndVerified: isAccessibleOnlyIfLoggedInAndVerified,
6766
isAccessibleOnlyIfLoggedOut: isAccessibleOnlyIfLoggedOut,
6867
isRedirectable: isRedirectable,
6968
internalParameters: internalParameters,
@@ -79,7 +78,7 @@ Future<void> generateScreen({
7978
[
8079
controllerTemplate,
8180
screenTemplate,
82-
viewTemplate,
81+
stateTemplate,
8382
],
8483
insightMappers,
8584
);

pubspec.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
name: df_generate_screen
1414
description: A tool to generate ready-made screen templates for your Flutter app (uses df_sceen)
15-
version: 0.4.1
15+
version: 0.5.0
1616
repository: https://github.com/devcetra/df_generate_screen
1717
funding:
1818
- https://www.buymeacoffee.com/robmllze
@@ -35,7 +35,7 @@ dependencies:
3535
df_config: ^0.5.3
3636
df_gen_core: ^0.4.5
3737
df_generate_dart_indexes: ^0.4.1
38-
df_generate_dart_models_core: ^0.6.10
38+
df_generate_dart_models_core: ^0.8.0
3939
df_log: ^0.2.4
4040
df_screen_core: ^0.3.0
4141
df_string: ^0.2.3
@@ -54,6 +54,6 @@ dev_dependencies:
5454
## -----------------------------------------------------------------------------
5555

5656
executables:
57-
dfscr: dfscr-v5
58-
dfscr-access: dfscr-access-v5
59-
dfscr-bindings: dfscr-bindings-v5
57+
gen-screen: dfscr-v5
58+
gen-screen-access: dfscr-access-v5
59+
gen-screen-bindings: dfscr-bindings-v5

templates/v6/access.dart.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
```dart
2+
//.title
3+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
4+
//
5+
// GENERATED - DO NOT MODIFY BY HAND
6+
// See: https://github.com/DevCetra/df_generate_screen
7+
//
8+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
9+
//.title~
10+
11+
// ignore: depend_on_referenced_packages
12+
import 'package:df_screen/df_screen.dart';
13+
14+
import '_index.g.dart';
15+
16+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
17+
18+
/// A list of all screen routes in the app.
19+
final generatedScreenRoutes = [
20+
___GENERATED_SCREEN_ROUTES___,
21+
];
22+
23+
/// A list of function references. Each function returns a corresponding [Screen]
24+
/// for a given [ModelScreenConfiguration] or `null` if the given configuration
25+
/// does not match or access is denied to the screen.
26+
const SCREEN_MAKERS = [
27+
___SCREEN_MAKERS___,
28+
];
29+
30+
/// Finds the screen that corresponds to [configuration]. It iterates through
31+
/// the list of screen makers and calls each one with the provided [configuration]
32+
/// and authentication states ([isLoggedInAndVerified], [isLoggedIn], [isLoggedOut]).
33+
/// If a screen is found that matches the configuration and is accessible, it is
34+
/// returned. Otherwise, `null` is returned.
35+
Screen? findScreenFromConfiguration({
36+
required ModelScreenConfiguration configuration,
37+
required bool? isLoggedInAndVerified,
38+
required bool? isLoggedIn,
39+
required bool? isLoggedOut,
40+
}) {
41+
for (final screenMaker in SCREEN_MAKERS) {
42+
final screen = screenMaker.call(
43+
configuration,
44+
isLoggedInAndVerified ?? false,
45+
isLoggedIn ?? false,
46+
isLoggedOut ?? true,
47+
);
48+
if (screen != null) {
49+
return screen;
50+
}
51+
}
52+
return null;
53+
}
54+
55+
/// Finds the screen that corresponds to [configuration], considering
56+
/// the user's authentication state ([loggedIn], [verified]). It determines
57+
/// whether the user is logged in, verified, or logged out, and then calls
58+
/// `findScreenFromConfiguration` with these states. If a matching screen is
59+
/// found and accessible, it is returned; otherwise, `null` is returned.
60+
Screen? findScreenFromConfigurationAndAuthService({
61+
required ModelScreenConfiguration configuration,
62+
required bool loggedIn,
63+
required bool verified,
64+
}) {
65+
final loggedOut = !loggedIn;
66+
final loggedInAndVerified = loggedIn && verified;
67+
return findScreenFromConfiguration(
68+
configuration: configuration,
69+
isLoggedInAndVerified: loggedInAndVerified,
70+
isLoggedIn: loggedIn,
71+
isLoggedOut: loggedOut,
72+
);
73+
}
74+
75+
/// Translates the current URL into a [ModelScreenConfiguration], considering
76+
/// the user's authentication state ([loggedIn], [verified]). It calls
77+
/// `findScreenFromConfigurationAndAuthService` with the current URL's query
78+
/// parameters and path, along with the user's authentication states. If a
79+
/// matching screen configuration is found and accessible, it is returned;
80+
/// otherwise, `null` is returned.
81+
ModelScreenConfiguration? currentUrlToConfiguration({
82+
required bool loggedIn,
83+
required bool verified,
84+
}) {
85+
return findScreenFromConfigurationAndAuthService(
86+
configuration: ModelScreenConfiguration(
87+
args: Uri.base.queryParameters,
88+
path: Uri.base.path,
89+
),
90+
loggedIn: loggedIn,
91+
verified: verified,
92+
)?.configuration;
93+
}
94+
95+
/// Translates the current URL into a [ModelScreenConfiguration] under the
96+
/// assumption that the user is logged in and verified. It calls
97+
/// `findScreenFromConfiguration` with the current URL's query parameters and
98+
/// path, assuming the user is logged in and verified. If a corresponding
99+
/// screen is accessible, its configuration is returned; otherwise, `null` is
100+
/// returned.
101+
ModelScreenConfiguration? currentUrlToLoginConfiguration() {
102+
return findScreenFromConfiguration(
103+
configuration: ModelScreenConfiguration(
104+
args: Uri.base.queryParameters,
105+
path: Uri.base.path,
106+
),
107+
isLoggedInAndVerified: true,
108+
isLoggedIn: true,
109+
isLoggedOut: false,
110+
)?.configuration;
111+
}
112+
113+
/// Translates the current URL into a [ModelScreenConfiguration] under the
114+
/// assumption that the user is logged out. It calls `findScreenFromConfiguration`
115+
/// with the current URL's query parameters and path, assuming the user is
116+
/// logged out. If a corresponding screen is accessible, its configuration is
117+
/// returned; otherwise, `null` is returned.
118+
ModelScreenConfiguration? currentUrlToLogoutConfiguration() {
119+
return findScreenFromConfiguration(
120+
configuration: ModelScreenConfiguration(
121+
args: Uri.base.queryParameters,
122+
path: Uri.base.path,
123+
),
124+
isLoggedInAndVerified: false,
125+
isLoggedIn: false,
126+
isLoggedOut: true,
127+
)?.configuration;
128+
}
129+
```

0 commit comments

Comments
 (0)