Skip to content

Commit 1fbc5be

Browse files
committed
update
1 parent dd926b0 commit 1fbc5be

16 files changed

+704
-22
lines changed

bin/gen_screen_access.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main(List<String> args) async {
1818
await genScreenAccessApp(
1919
args,
2020
defaultTemplates: const [
21-
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/access.dart.md',
21+
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/_access.g.dart.md',
2222
],
2323
);
2424
}

bin/gen_screen_bindings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main(List<String> args) async {
1818
await genScreenBindingsApp(
1919
args,
2020
defaultTemplates: const [
21-
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/_bindings.dart.md',
21+
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/_bindings.g.dart.md',
2222
],
2323
);
2424
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// GENERATED - DO NOT MODIFY BY HAND
5+
// See: https://github.com/DevCetra/df_generate_screen
6+
//
7+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
8+
//.title~
9+
10+
// ignore: depend_on_referenced_packages
11+
import 'package:df_screen/df_screen.dart';
12+
13+
// This file should export all your screen widgets. If it doesn’t exist,
14+
// generate it using the command “gen-indexes-dart -i .”, available via
15+
// this package: https://pub.dev/packages/df_generate_dart_indexes
16+
import '_index.g.dart';
17+
18+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
19+
20+
/// A list of all screen routes in the app.
21+
final generatedScreenRoutes = [
22+
generatedExampleScreenRoute,
23+
generatedExampleScreenRoute,
24+
];
25+
26+
/// A list of function references. Each function returns a corresponding [Screen]
27+
/// for a given [ModelScreenConfiguration] or `null` if the given configuration
28+
/// does not match or access is denied to the screen.
29+
const SCREEN_MAKERS = [
30+
makerExampleScreen,
31+
makerExampleScreen,
32+
];
33+
34+
/// Finds the screen that corresponds to [configuration]. It iterates through
35+
/// the list of screen makers and calls each one with the provided [configuration]
36+
/// and authentication states ([isLoggedInAndVerified], [isLoggedIn], [isLoggedOut]).
37+
/// If a screen is found that matches the configuration and is accessible, it is
38+
/// returned. Otherwise, `null` is returned.
39+
Screen? findScreenFromConfiguration({
40+
required ModelScreenConfiguration configuration,
41+
required bool? isLoggedInAndVerified,
42+
required bool? isLoggedIn,
43+
required bool? isLoggedOut,
44+
}) {
45+
for (final screenMaker in SCREEN_MAKERS) {
46+
final screen = screenMaker.call(
47+
configuration,
48+
isLoggedInAndVerified ?? false,
49+
isLoggedIn ?? false,
50+
isLoggedOut ?? true,
51+
);
52+
if (screen != null) {
53+
return screen;
54+
}
55+
}
56+
return null;
57+
}
58+
59+
/// Finds the screen that corresponds to [configuration], considering
60+
/// the user's authentication state ([loggedIn], [verified]). It determines
61+
/// whether the user is logged in, verified, or logged out, and then calls
62+
/// `findScreenFromConfiguration` with these states. If a matching screen is
63+
/// found and accessible, it is returned; otherwise, `null` is returned.
64+
Screen? findScreenFromConfigurationAndAuthService({
65+
required ModelScreenConfiguration configuration,
66+
required bool loggedIn,
67+
required bool verified,
68+
}) {
69+
final loggedOut = !loggedIn;
70+
final loggedInAndVerified = loggedIn && verified;
71+
return findScreenFromConfiguration(
72+
configuration: configuration,
73+
isLoggedInAndVerified: loggedInAndVerified,
74+
isLoggedIn: loggedIn,
75+
isLoggedOut: loggedOut,
76+
);
77+
}
78+
79+
/// Translates the current URL into a [ModelScreenConfiguration], considering
80+
/// the user's authentication state ([loggedIn], [verified]). It calls
81+
/// `findScreenFromConfigurationAndAuthService` with the current URL's query
82+
/// parameters and path, along with the user's authentication states. If a
83+
/// matching screen configuration is found and accessible, it is returned;
84+
/// otherwise, `null` is returned.
85+
ModelScreenConfiguration? currentUrlToConfiguration({
86+
required bool loggedIn,
87+
required bool verified,
88+
}) {
89+
return letAsOrNull<ModelScreenConfiguration>(
90+
findScreenFromConfigurationAndAuthService(
91+
configuration: ModelScreenConfiguration(
92+
args: Uri.base.queryParameters,
93+
path: Uri.base.path,
94+
),
95+
loggedIn: loggedIn,
96+
verified: verified,
97+
)?.extra,
98+
);
99+
}
100+
101+
/// Translates the current URL into a [ModelScreenConfiguration] under the
102+
/// assumption that the user is logged in and verified. It calls
103+
/// `findScreenFromConfiguration` with the current URL's query parameters and
104+
/// path, assuming the user is logged in and verified. If a corresponding
105+
/// screen is accessible, its configuration is returned; otherwise, `null` is
106+
/// returned.
107+
ModelScreenConfiguration? currentUrlToLoginConfiguration() {
108+
return letAsOrNull<ModelScreenConfiguration>(
109+
findScreenFromConfiguration(
110+
configuration: ModelScreenConfiguration(
111+
args: Uri.base.queryParameters,
112+
path: Uri.base.path,
113+
),
114+
isLoggedInAndVerified: true,
115+
isLoggedIn: true,
116+
isLoggedOut: false,
117+
)?.extra,
118+
);
119+
}
120+
121+
/// Translates the current URL into a [ModelScreenConfiguration] under the
122+
/// assumption that the user is logged out. It calls `findScreenFromConfiguration`
123+
/// with the current URL's query parameters and path, assuming the user is
124+
/// logged out. If a corresponding screen is accessible, its configuration is
125+
/// returned; otherwise, `null` is returned.
126+
ModelScreenConfiguration? currentUrlToLogoutConfiguration() {
127+
return letAsOrNull<ModelScreenConfiguration>(
128+
findScreenFromConfiguration(
129+
configuration: ModelScreenConfiguration(
130+
args: Uri.base.queryParameters,
131+
path: Uri.base.path,
132+
),
133+
isLoggedInAndVerified: false,
134+
isLoggedIn: false,
135+
isLoggedOut: true,
136+
)?.extra,
137+
);
138+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// GENERATED - DO NOT MODIFY BY HAND
5+
// See: https://github.com/DevCetra/df_generate_dart_indexes
6+
//
7+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
8+
//.title~
9+
10+
export './example_screen/widget.dart';
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
//.title
2+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
3+
//
4+
// GENERATED - DO NOT MODIFY BY HAND
5+
// See: https://github.com/DevCetra/df_generate_screen
6+
//
7+
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
8+
//.title~
9+
10+
// ignore_for_file: unused_element
11+
// ignore_for_file: constant_identifier_names,
12+
13+
part of 'widget.dart';
14+
15+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
16+
17+
final _globalKey = GlobalKey<_State>();
18+
19+
/// Serves as the blueprint for the [ExampleScreen] screen.
20+
/// It outlines the screen's properties and behaviors prior to routing.
21+
class ExampleScreenConfiguration extends ModelScreenConfiguration {
22+
//
23+
//
24+
//
25+
26+
factory ExampleScreenConfiguration({
27+
Map<dynamic, dynamic>? $args,
28+
}) {
29+
return ExampleScreenConfiguration.optional(
30+
args: {
31+
...?$args,
32+
}.nonNulls,
33+
);
34+
}
35+
36+
//
37+
//
38+
//
39+
40+
ExampleScreenConfiguration.optional({
41+
Map<dynamic, dynamic>? args,
42+
}) : super.optional(
43+
title: null,
44+
path: _PATH,
45+
args: args ?? {},
46+
isAccessibleOnlyIfLoggedInAndVerified:
47+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
48+
isAccessibleOnlyIfLoggedIn: _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
49+
isAccessibleOnlyIfLoggedOut: _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
50+
isRedirectable: _IS_REDIRECTABLE,
51+
);
52+
53+
//
54+
//
55+
//
56+
57+
/// The name of the corresponding [Screen] class.
58+
static const WIDGET = _CLASS;
59+
60+
/// The path of the corresponding [Screen].
61+
static const PATH = _PATH;
62+
63+
/// The segment of the corresponding [Screen] path.
64+
static const SEGMENT = _SEGMENT;
65+
66+
/// The translation key for the corresponding [Screen].
67+
static const TR_KEY = _TR_KEY;
68+
69+
/// Whether the corresponding [Screen] is only accessible if the user is logged in and verified.
70+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_IN =
71+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN;
72+
73+
/// Whether the corresponding [Screen] is only accessible if the user is logged in.
74+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED =
75+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED;
76+
77+
/// Whether the corresponding [Screen] is only accessible if the user is logged out.
78+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT =
79+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT;
80+
81+
/// Whether the corresponding [Screen] is redirectable, i.e., if it can be requested from the browser URL.
82+
static const IS_REDIRECTABLE = _IS_REDIRECTABLE;
83+
}
84+
85+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
86+
87+
/// Extend this class to create a controller for the [ExampleScreen] screen.
88+
abstract base class _ControllerBroker<T1 extends ExampleScreen,
89+
T2 extends _State> extends ScreenController<ExampleScreenConfiguration> {
90+
/// The [Screen] that corresponds to `this` controller.
91+
late final screen = super.superScreen as T1;
92+
93+
/// The [State] that corresponds to `this` controller.
94+
late final state = super.superState as T2;
95+
96+
/// The [ModelScreenConfiguration] that corresponds to `this` controller.
97+
late final configuration = screen.extra is ExampleScreenConfiguration
98+
? screen.extra as ExampleScreenConfiguration
99+
: ExampleScreenConfiguration.optional(
100+
args: screen.extra is ModelScreenConfiguration
101+
? (screen.extra as ModelScreenConfiguration).args
102+
: {},
103+
);
104+
105+
_ControllerBroker(
106+
super.superScreen,
107+
super.superState, [
108+
super.extra,
109+
]);
110+
}
111+
112+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
113+
114+
/// The generated [GoRoute] that corresponds to [ExampleScreen].
115+
final generatedExampleScreenRoute = GoRoute(
116+
path: _SEGMENT,
117+
pageBuilder: (context, state) {
118+
final extra = letAsOrNull<ModelScreenConfiguration>(state.extra);
119+
return NoTransitionPage(
120+
key: state.pageKey,
121+
child: ExampleScreen(
122+
key: _globalKey,
123+
extra: extra ??
124+
urlToScreenConfiguration(
125+
url: state.uri,
126+
isAccessibleOnlyIfLoggedIn:
127+
ExampleScreenConfiguration.IS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
128+
isAccessibleOnlyIfLoggedInAndVerified: ExampleScreenConfiguration
129+
.IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
130+
isAccessibleOnlyIfLoggedOut:
131+
ExampleScreenConfiguration.IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
132+
isRedirectable: ExampleScreenConfiguration.IS_REDIRECTABLE,
133+
title: null,
134+
),
135+
),
136+
);
137+
},
138+
);
139+
140+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
141+
142+
/// Returns a [ExampleScreen] instance if the [configuration] is of type
143+
/// [ExampleScreenConfiguration] and if the current authentication status matches
144+
/// [isLoggedInAndVerified], [isLoggedIn], and [isLoggedOut].
145+
Screen? makerExampleScreen(
146+
ModelScreenConfiguration extra,
147+
bool isLoggedInAndVerified,
148+
bool isLoggedIn,
149+
bool isLoggedOut,
150+
) {
151+
if ((_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED &&
152+
!isLoggedInAndVerified) ||
153+
(_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN && !isLoggedIn) ||
154+
(_IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT && !isLoggedOut)) {
155+
return null;
156+
}
157+
if (extra is ExampleScreenConfiguration) {
158+
return ExampleScreen(
159+
key: _globalKey,
160+
extra: extra,
161+
);
162+
}
163+
if (RegExp(r'^(' + _PATH + r')([?/].*)?$')
164+
.hasMatch(Uri.decodeComponent(extra.path ?? ''))) {
165+
final temp = ExampleScreenConfiguration.optional(
166+
args: extra.args,
167+
);
168+
return ExampleScreen(
169+
key: _globalKey,
170+
extra: temp,
171+
);
172+
}
173+
return null;
174+
}
175+
176+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
177+
178+
/// A controller type corresponding to [ExampleScreen].
179+
typedef TExampleScreenController = _ControllerBroker<ExampleScreen, _State>;
180+
181+
/// A [AdaptiveScreenState] type corresponding to [ExampleScreen].
182+
typedef TAdaptiveExampleScreenState = AdaptiveScreenState<ExampleScreen,
183+
ExampleScreenConfiguration, ExampleScreenController>;
184+
185+
/// A [ScreenState] type corresponding to [ExampleScreen].
186+
typedef TExampleScreenState = ScreenState<ExampleScreen,
187+
ExampleScreenConfiguration, ExampleScreenController>;
188+
189+
/// A [ScreenPageState] type corresponding to [ExampleScreen].
190+
typedef TExampleScreenPageState<T extends ScreenPage>
191+
= ScreenPageState<T, ExampleScreenConfiguration, ExampleScreenController>;
192+
193+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
194+
195+
base class _ExampleScreen extends Screen {
196+
const _ExampleScreen({
197+
required super.key,
198+
required super.extra,
199+
super.controllerTimeout = Duration.zero,
200+
});
201+
202+
@override
203+
createState() => _State();
204+
205+
@override
206+
createController(
207+
Screen screen,
208+
ScreenState state,
209+
) {
210+
return ExampleScreenController(screen, state);
211+
}
212+
}
213+
214+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
215+
216+
// The following constants are set by the generator based on the provided
217+
// options. Together they form the behavior of the generated screen.
218+
219+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED = false;
220+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN = false;
221+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT = false;
222+
const _IS_REDIRECTABLE = false;
223+
const _CLASS = 'ExampleScreen';
224+
const _SEGMENT = 'example';
225+
const _PATH = '/$_SEGMENT';
226+
const _TR_KEY = 'screens.ExampleScreen';
227+
const _DEFAULT_TITLE = 'ExampleScreen';

0 commit comments

Comments
 (0)