Skip to content

Commit 712d7f3

Browse files
committed
chore: Update templates
1 parent 5a45444 commit 712d7f3

File tree

12 files changed

+1025
-44
lines changed

12 files changed

+1025
-44
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
```dart
2+
//.title
3+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
4+
//
5+
// GENERATED - DO NOT MODIFY BY HAND
6+
// See: https://github.com/robmllze/df_generate_screen
7+
//
8+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
9+
//.title~
10+
11+
import '/_common.dart';
12+
13+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
/// A list of all screen routes in the app.
16+
final generatedScreenRoutes = [
17+
___GENERATED_SCREEN_ROUTES___,
18+
];
19+
20+
/// A list of function references. Each returns a corresponding screen for a
21+
/// given configuration or `null` if the given configuration does not match or
22+
/// access is denied to the screen.
23+
const SCREEN_MAKERS = [
24+
___SCREEN_MAKERS___,
25+
];
26+
27+
/// Finds the screen that corresponds to [configuration]. Returns the
28+
/// corresponding screen or `null` if none are found or access is denied to
29+
/// the screen.
30+
Screen? findScreenFromConfiguration({
31+
required ModelScreenConfiguration configuration,
32+
required bool? isLoggedInAndVerified,
33+
required bool? isLoggedIn,
34+
required bool? isLoggedOut,
35+
}) {
36+
for (final screenMaker in SCREEN_MAKERS) {
37+
final screen = screenMaker.call(
38+
configuration,
39+
isLoggedInAndVerified ?? false,
40+
isLoggedIn ?? false,
41+
isLoggedOut ?? true,
42+
);
43+
if (screen != null) {
44+
return screen;
45+
}
46+
}
47+
return null;
48+
}
49+
50+
/// Finds the screen that corresponds to [configuration]. Returns the
51+
/// corresponding screen or `null` if none are found or access is denied to
52+
/// the screen.
53+
Screen? findScreenFromConfigurationAndAuthService({
54+
required ModelScreenConfiguration configuration,
55+
required AuthServiceInterface? authServiceBroker,
56+
}) {
57+
return findScreenFromConfiguration(
58+
configuration: configuration,
59+
isLoggedInAndVerified: authServiceBroker?.loggedInAndEmailVerified ?? false,
60+
isLoggedIn: authServiceBroker?.loggedIn ?? false,
61+
isLoggedOut: authServiceBroker?.loggedOut ?? true,
62+
);
63+
}
64+
65+
/// Translates the current URL into a [ModelScreenConfiguration], considering
66+
/// the user's authentication state via [authServiceBroker]. Returns the
67+
/// matching screen configuration if accessible; otherwise, `null`.
68+
ModelScreenConfiguration? currentUrlToConfiguration({
69+
required AuthServiceInterface? authServiceBroker,
70+
}) {
71+
return findScreenFromConfigurationAndAuthService(
72+
configuration: ModelScreenConfiguration(
73+
args: Uri.base.queryParameters,
74+
path: Uri.base.path,
75+
),
76+
authServiceBroker: authServiceBroker,
77+
)?.configuration;
78+
}
79+
80+
/// Translates the current URL into a [ModelScreenConfiguration] under the
81+
/// assumption that the user is **logged in and email verified**. If a
82+
/// corresponding screen is accessible, returns its configuration; otherwise,
83+
/// returns `null`.
84+
ModelScreenConfiguration? currentUrlToLoginConfiguration() {
85+
return findScreenFromConfiguration(
86+
configuration: ModelScreenConfiguration(
87+
args: Uri.base.queryParameters,
88+
path: Uri.base.path,
89+
),
90+
isLoggedInAndVerified: true,
91+
isLoggedIn: true,
92+
isLoggedOut: false,
93+
)?.configuration;
94+
}
95+
96+
/// Translates the current URL into a [ModelScreenConfiguration] under the
97+
/// assumption that the user is **logged out**. If a corresponding screen is
98+
/// accessible, returns its configuration; otherwise, returns `null`.
99+
ModelScreenConfiguration? currentUrlToLogoutConfiguration() {
100+
return findScreenFromConfiguration(
101+
configuration: ModelScreenConfiguration(
102+
args: Uri.base.queryParameters,
103+
path: Uri.base.path,
104+
),
105+
isLoggedInAndVerified: false,
106+
isLoggedIn: false,
107+
isLoggedOut: true,
108+
)?.configuration;
109+
}
110+
```
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
```dart
2+
//.title
3+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
4+
//
5+
// GENERATED - DO NOT MODIFY BY HAND
6+
// See: https://github.com/robmllze/df_generate_screen
7+
//
8+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
9+
//.title~
10+
11+
part of '___CLASS_FILE___';
12+
13+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
final _globalKey = GlobalKey<_View>();
16+
17+
/// Serves as the blueprint for the [___CLASS___] screen.
18+
/// It outlines the screen's properties and behaviors prior to routing.
19+
class ___CONFIGURATION_CLASS___ extends ModelScreenConfiguration {
20+
//
21+
//
22+
//
23+
24+
___IP0___
25+
___QP0___
26+
27+
factory ___CONFIGURATION_CLASS___({
28+
___IP1___
29+
___QP1___
30+
Map<dynamic, dynamic>? $args,
31+
}) {
32+
return ___CONFIGURATION_CLASS___.c2(
33+
args: {
34+
___IP2___
35+
___QP2___
36+
...?$args,
37+
}.nonNulls,
38+
);
39+
}
40+
41+
//
42+
//
43+
//
44+
45+
___CONFIGURATION_CLASS___.c2({
46+
Map<dynamic, dynamic>? args,
47+
}): super.c2(
48+
title: translatedTitle,
49+
path: _PATH,
50+
args: args ?? {},
51+
isAccessibleOnlyIfLoggedInAndVerified: _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
52+
isAccessibleOnlyIfLoggedIn: _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
53+
isAccessibleOnlyIfLoggedOut: _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
54+
isRedirectable: _IS_REDIRECTABLE,
55+
);
56+
57+
//
58+
//
59+
//
60+
61+
@override
62+
String get title => translatedTitle;
63+
64+
//
65+
//
66+
//
67+
68+
/// The name of the corresponding [Screen] class.
69+
static const CLASS = _CLASS;
70+
71+
/// The path of the corresponding [Screen].
72+
static const PATH = _PATH;
73+
74+
/// The segment of the corresponding [Screen] path.
75+
static const SEGMENT = _SEGMENT;
76+
77+
/// The translation key for the corresponding [Screen].
78+
static const TR_KEY = _TR_KEY;
79+
80+
/// Whether the corresponding [Screen] is only accessible if the user is logged in and verified.
81+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_IN = _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN;
82+
83+
/// Whether the corresponding [Screen] is only accessible if the user is logged in.
84+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED = _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED;
85+
86+
/// Whether the corresponding [Screen] is only accessible if the user is logged out.
87+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT = _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT;
88+
89+
/// Whether the corresponding [Screen] is redirectable, i.e., if it can be requested from the browser URL.
90+
static const IS_REDIRECTABLE = _IS_REDIRECTABLE;
91+
92+
/// The title of the corresponding [Screen].
93+
static String get translatedTitle => screenTr('$_DEFAULT_TITLE||title');
94+
95+
/// Translates the provided [key] using the screen's translation key.
96+
static String screenTr(String key, {Map<dynamic, dynamic> args = const {}}) {
97+
return key.splitByLastOccurrenceOf('||').join('||$_TR_KEY.').tr(args: args);
98+
}
99+
}
100+
101+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
102+
103+
/// Extend this class to create a controller for the [___CLASS___] screen.
104+
abstract base class _ControllerBroker<T1 extends ___CLASS___, T2 extends _View>
105+
extends ScreenController<___CONFIGURATION_CLASS___> {
106+
107+
/// The [Screen] that corresponds to `this` controller.
108+
late final screen = super.superScreen as T1;
109+
110+
/// The [State] that corresponds to `this` controller.
111+
late final state = super.superState as T2;
112+
113+
/// The [ModelScreenConfiguration] that corresponds to `this` controller.
114+
late final configuration = super.internalConfiguration ?? ___CONFIGURATION_CLASS___.c2(
115+
args: screen.configuration?.args,
116+
);
117+
118+
_ControllerBroker(
119+
super.superScreen,
120+
super.superState, [
121+
super.internalConfiguration,
122+
]);
123+
}
124+
125+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
126+
127+
/// The generated [GoRoute] that corresponds to [___CLASS___].
128+
final generated___CLASS___Route = GoRoute(
129+
path: _SEGMENT,
130+
pageBuilder: (context, state) {
131+
final extraConfiguration = letAs<ModelScreenConfiguration>(state.extra);
132+
final urlConfiguration = urlToScreenConfiguration(
133+
url: state.uri,
134+
isAccessibleOnlyIfLoggedIn: ___CONFIGURATION_CLASS___.IS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
135+
isAccessibleOnlyIfLoggedInAndVerified: ___CONFIGURATION_CLASS___.IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
136+
isAccessibleOnlyIfLoggedOut: ___CONFIGURATION_CLASS___.IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
137+
isRedirectable: ___CONFIGURATION_CLASS___.IS_REDIRECTABLE,
138+
title: ___CONFIGURATION_CLASS___.translatedTitle,
139+
);
140+
final configuration = extraConfiguration ?? urlConfiguration;
141+
return NoTransitionPage(
142+
key: state.pageKey,
143+
child: ___CLASS___(
144+
key: _globalKey,
145+
configuration: configuration,
146+
),
147+
);
148+
},
149+
);
150+
151+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
152+
153+
extension _ScreenTr on String {
154+
/// Translates this [String] using the translation key '_TR_KEY'. Optionally,
155+
/// pass [args] to replace placeholders in this String denoted by `{key}` in
156+
/// the translation.
157+
// ignore: unused_element
158+
String screenTr({Map<dynamic, dynamic> args = const {}}) {
159+
return ___CONFIGURATION_CLASS___.screenTr(this, args: args);
160+
}
161+
}
162+
163+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
164+
165+
/// Returns a [___CLASS___] instance if the [configuration] is of type
166+
/// [___CONFIGURATION_CLASS___] and if the current authentication status matches
167+
/// [isLoggedInAndVerified], [isLoggedIn], and [isLoggedOut].
168+
Screen? maker___CLASS___(
169+
ModelScreenConfiguration configuration,
170+
bool isLoggedInAndVerified,
171+
bool isLoggedIn,
172+
bool isLoggedOut,
173+
) {
174+
if ((_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED && !isLoggedInAndVerified) || (_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN && !isLoggedIn) || (_IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT && !isLoggedOut)) {
175+
return null;
176+
}
177+
if (configuration is ___CONFIGURATION_CLASS___) {
178+
return ___CLASS___(
179+
key: _globalKey,
180+
configuration: configuration,
181+
);
182+
}
183+
if (RegExp(r'^(' + _PATH + r')([?/].*)?$')
184+
.hasMatch(Uri.decodeComponent(configuration.path ?? ''))) {
185+
final temp = ___CONFIGURATION_CLASS___.c2(
186+
args: configuration.args,
187+
);
188+
return ___CLASS___(
189+
key: _globalKey,
190+
configuration: temp,
191+
);
192+
}
193+
return null;
194+
}
195+
196+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
197+
198+
/// The controller [Type] corresponding to [___CLASS___].
199+
typedef T___CLASS___Controller = _ControllerBroker<___CLASS___, _View>;
200+
201+
/// The [ScreenView] [Type] corresponding to [___CLASS___].
202+
typedef T___CLASS___View = ScreenView<___CLASS___, ___CONFIGURATION_CLASS___, ___CLASS___Controller>;
203+
204+
/// The [ScreenPageView] [Type] corresponding to [___CLASS___].
205+
typedef T___CLASS___PageView<T extends ScreenPage> = ScreenPageView<T, ___CONFIGURATION_CLASS___, ___CLASS___Controller>;
206+
207+
208+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
209+
210+
// The following constants are set by the generator based on the provided
211+
// options. Together they form the behavior of the generated screen.
212+
213+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED = ___IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED___;
214+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN = ___IS_ACCESSIBLE_ONLY_IF_LOGGED_IN___;
215+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT = ___IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT___;
216+
const _IS_REDIRECTABLE = ___IS_REDIRECTABLE___;
217+
const _CLASS = '___CLASS___';
218+
const _SEGMENT = '___SCREEN_SEGMENT___';
219+
const _PATH = '/$_SEGMENT';
220+
const _TR_KEY = 'screens.___CLASS___';
221+
const _DEFAULT_TITLE = '___DEFAULT_TITLE___';
222+
```

0 commit comments

Comments
 (0)