Skip to content

Commit ced63e0

Browse files
committed
update
1 parent a06a6e0 commit ced63e0

File tree

7 files changed

+238
-16
lines changed

7 files changed

+238
-16
lines changed

bin/gen_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void main(List<String> args) async {
1919
args,
2020
defaultTemplates: const [
2121
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/_state.dart.md',
22-
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/{widget}.dart.md',
22+
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/widget.dart.md',
2323
'https://raw.githubusercontent.com/robmllze/df_generate_screen/main/templates/v1/_controller.dart.md',
2424
],
2525
);
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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+
12+
part of 'widget.dart';
13+
14+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
15+
16+
final _globalKey = GlobalKey<_State>();
17+
18+
/// Serves as the blueprint for the [___WIDGET_NAME___] screen.
19+
/// It outlines the screen's properties and behaviors prior to routing.
20+
class ___WIDGET_NAME___Configuration extends ModelScreenConfiguration {
21+
//
22+
//
23+
//
24+
25+
factory ___WIDGET_NAME___Configuration({
26+
Map<dynamic, dynamic>? $args,
27+
}) {
28+
return ___WIDGET_NAME___Configuration.optional(
29+
args: {
30+
...?$args,
31+
}.nonNulls,
32+
);
33+
}
34+
35+
//
36+
//
37+
//
38+
39+
___WIDGET_NAME___Configuration.optional({
40+
Map<dynamic, dynamic>? args,
41+
}) : super.optional(
42+
title: null,
43+
path: _PATH,
44+
args: args ?? {},
45+
isAccessibleOnlyIfLoggedInAndVerified:
46+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
47+
isAccessibleOnlyIfLoggedIn: _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
48+
isAccessibleOnlyIfLoggedOut: _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
49+
isRedirectable: _IS_REDIRECTABLE,
50+
);
51+
52+
//
53+
//
54+
//
55+
56+
/// The name of the corresponding [Screen] class.
57+
static const WIDGET = _CLASS;
58+
59+
/// The path of the corresponding [Screen].
60+
static const PATH = _PATH;
61+
62+
/// The segment of the corresponding [Screen] path.
63+
static const SEGMENT = _SEGMENT;
64+
65+
/// The translation key for the corresponding [Screen].
66+
static const TR_KEY = _TR_KEY;
67+
68+
/// Whether the corresponding [Screen] is only accessible if the user is logged in and verified.
69+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_IN =
70+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN;
71+
72+
/// Whether the corresponding [Screen] is only accessible if the user is logged in.
73+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED =
74+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED;
75+
76+
/// Whether the corresponding [Screen] is only accessible if the user is logged out.
77+
static const IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT =
78+
_IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT;
79+
80+
/// Whether the corresponding [Screen] is redirectable, i.e., if it can be requested from the browser URL.
81+
static const IS_REDIRECTABLE = _IS_REDIRECTABLE;
82+
}
83+
84+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
85+
86+
/// Extend this class to create a controller for the [___WIDGET_NAME___] screen.
87+
abstract base class _ControllerBroker<T1 extends ___WIDGET_NAME___,
88+
T2 extends _State>
89+
extends ScreenController<___WIDGET_NAME___Configuration> {
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 ___WIDGET_NAME___Configuration
98+
? screen.extra as ___WIDGET_NAME___Configuration
99+
: ___WIDGET_NAME___Configuration.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 [___WIDGET_NAME___].
115+
final generated___WIDGET_NAME___Route = GoRoute(
116+
path: _SEGMENT,
117+
pageBuilder: (context, state) {
118+
final extra = letAsOrNull<ModelScreenConfiguration>(state.extra);
119+
return NoTransitionPage(
120+
key: state.pageKey,
121+
child: ___WIDGET_NAME___(
122+
key: _globalKey,
123+
extra: extra ??
124+
urlToScreenConfiguration(
125+
url: state.uri,
126+
isAccessibleOnlyIfLoggedIn: ___WIDGET_NAME___Configuration
127+
.IS_ACCESSIBLE_ONLY_IF_LOGGED_IN,
128+
isAccessibleOnlyIfLoggedInAndVerified:
129+
___WIDGET_NAME___Configuration
130+
.IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED,
131+
isAccessibleOnlyIfLoggedOut: ___WIDGET_NAME___Configuration
132+
.IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT,
133+
isRedirectable: ___WIDGET_NAME___Configuration.IS_REDIRECTABLE,
134+
title: null,
135+
),
136+
),
137+
);
138+
},
139+
);
140+
141+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
142+
143+
/// Returns a [___WIDGET_NAME___] instance if the [configuration] is of type
144+
/// [___WIDGET_NAME___Configuration] and if the current authentication status matches
145+
/// [isLoggedInAndVerified], [isLoggedIn], and [isLoggedOut].
146+
Screen? maker___WIDGET_NAME___(
147+
ModelScreenConfiguration extra,
148+
bool isLoggedInAndVerified,
149+
bool isLoggedIn,
150+
bool isLoggedOut,
151+
) {
152+
if ((_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED &&
153+
!isLoggedInAndVerified) ||
154+
(_IS_ACCESSIBLE_ONLY_IF_LOGGED_IN && !isLoggedIn) ||
155+
(_IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT && !isLoggedOut)) {
156+
return null;
157+
}
158+
if (extra is ___WIDGET_NAME___Configuration) {
159+
return ___WIDGET_NAME___(
160+
key: _globalKey,
161+
extra: extra,
162+
);
163+
}
164+
if (RegExp(r'^(' + _PATH + r')([?/].*)?$')
165+
.hasMatch(Uri.decodeComponent(extra.path ?? ''))) {
166+
final temp = ___WIDGET_NAME___Configuration.optional(
167+
args: extra.args,
168+
);
169+
return ___WIDGET_NAME___(
170+
key: _globalKey,
171+
extra: temp,
172+
);
173+
}
174+
return null;
175+
}
176+
177+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
178+
179+
/// A controller type corresponding to [___WIDGET_NAME___].
180+
typedef T___WIDGET_NAME___Controller
181+
= _ControllerBroker<___WIDGET_NAME___, _State>;
182+
183+
/// A [AdaptiveScreenState] type corresponding to [___WIDGET_NAME___].
184+
typedef TAdaptive___WIDGET_NAME___State = AdaptiveScreenState<___WIDGET_NAME___,
185+
___WIDGET_NAME___Configuration, ___WIDGET_NAME___Controller>;
186+
187+
/// A [ScreenState] type corresponding to [___WIDGET_NAME___].
188+
typedef T___WIDGET_NAME___State = ScreenState<___WIDGET_NAME___,
189+
___WIDGET_NAME___Configuration, ___WIDGET_NAME___Controller>;
190+
191+
/// A [ScreenPageState] type corresponding to [___WIDGET_NAME___].
192+
typedef T___WIDGET_NAME___PageState<T extends ScreenPage> = ScreenPageState<T,
193+
___WIDGET_NAME___Configuration, ___WIDGET_NAME___Controller>;
194+
195+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
196+
197+
base class ____WIDGET_NAME___ extends Screen {
198+
const ____WIDGET_NAME___({
199+
required super.key,
200+
required super.extra,
201+
super.controllerTimeout = Duration.zero,
202+
});
203+
204+
@override
205+
createState() => _State();
206+
207+
@override
208+
createController(
209+
Screen screen,
210+
ScreenState state,
211+
) {
212+
return ___WIDGET_NAME___Controller(screen, state);
213+
}
214+
}
215+
216+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
217+
218+
// The following constants are set by the generator based on the provided
219+
// options. Together they form the behavior of the generated screen.
220+
221+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN_AND_VERIFIED = false;
222+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_IN = false;
223+
const _IS_ACCESSIBLE_ONLY_IF_LOGGED_OUT = false;
224+
const _IS_REDIRECTABLE = false;
225+
const _CLASS = '___WIDGET_NAME___';
226+
const _SEGMENT = '_example';
227+
const _PATH = '/$_SEGMENT';
228+
const _TR_KEY = 'screens.___WIDGET_NAME___';
229+
const _DEFAULT_TITLE = 'ExampleScreen';

bin/test_project/lib/screens/_controller.dart renamed to bin/test_project/lib/screens/example_screen/_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ final class ExampleScreenController extends TExampleScreenController {
88
//
99

1010
ExampleScreenController(super.screen, super.state);
11-
}
11+
}

bin/test_project/lib/screens/_state.dart renamed to bin/test_project/lib/screens/example_screen/_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ final class _State extends TExampleScreenState {
2121
return const Placeholder();
2222
}
2323
}
24-
*/
24+
*/

bin/test_project/lib/screens/widget.dart renamed to bin/test_project/lib/screens/example_screen/widget.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ part '_bindings.g.dart';
77
part '_controller.dart';
88
part '_state.dart';
99

10-
___PARTS___
11-
1210
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1311

1412
@GenerateScreenBindings()
15-
final class ___SCREEN_CLASS___ extends ____SCREEN_CLASS___ {
16-
const ___SCREEN_CLASS___({
17-
super.key,
18-
super.configuration,
19-
});
20-
}
13+
final class _ExampleScreen extends Screen {
14+
const _ExampleScreen();
15+
}

lib/src/gen_screen_bindings_app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ final _interpolator = TemplateInterpolator<ClassInsight<GenerateScreenBindings>>
214214
{
215215
'___SCREEN_KEY___': _screenKey,
216216
'___SCREEN_SEGMENT___': _screenSegment,
217-
'___WIDGET___': (insight) {
217+
'___WIDGET_NAME___': (insight) {
218218
return insight.className;
219219
},
220220
'___DEFAULT_TITLE___': (insight) {

templates/v1/widget.dart.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ part '_state.dart';
1111
1212
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1313
14-
@GenerateScreenBindings(
15-
___GENERATE_SCREEN_BINDINGS_ARGS___
16-
)
17-
final class ____WIDGET_NAME___ extends Screen {
14+
@GenerateScreenBindings()
15+
final class ____WIDGET_NAME___ extends ____WIDGET_NAME___ {
1816
const ____WIDGET_NAME___({
1917
super.key,
2018
super.configuration,

0 commit comments

Comments
 (0)