Skip to content

Commit

Permalink
feat: add variable app.dart location
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeBehr committed Aug 12, 2024
1 parent e4e2f5b commit 10faac1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions formigas_go_router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ $ mason list

For the brick to work, the Widget used as home route needs to be in a file named the same as the Widget but in snake_case.

The app.dart file has to be located at <b>lib/app/view/app.dart</b>.

The app.dart file must use the MaterialApp widget and the homeRoute must either be initialized directly in the constructor or as a variable inside this file.

If there is another widget than the MaterialApp the goRouter file is still created, but the app.dart file is not modified accordingly.
Expand All @@ -59,7 +57,7 @@ import 'package:counter_app/common/theme/custom_themes.dart';
import 'package:counter_app/features/counter/counter_controller_implementation.dart';
import 'package:counter_app/features/counter/counter_view.dart';
App extends StatelessWidget {
class App extends StatelessWidget {
const App({super.key});
@override
Expand Down
6 changes: 6 additions & 0 deletions formigas_go_router/brick.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ environment:
mason: ">=0.1.0-dev.53 <0.1.0"

vars:
app_directory:
description: The directory where the app.dart file is located.
type: string
default: lib/app/view
prompt: "Where is the app.dart file located?"

homepage_name:
type: string
description: The name of the homepage.
Expand Down
4 changes: 2 additions & 2 deletions formigas_go_router/hooks/post_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Future<void> run(HookContext context) async {

void _implementGoRouter(HookContext context) {
try {
String appFile = File('${Directory.current.path}/lib/app/view/app.dart')
String appFile = File('${Directory.current.path}/${context.vars['app_directory']}/app.dart')
.readAsStringSync();
appFile =
'import \'package:${context.vars['project_name']}/services/navigation_service/go_router.dart\';' +
'\n' +
appFile;
appFile = appFile.replaceAll('MaterialApp(', 'MaterialApp.router(');
appFile = _findHomeWidget(appFile, context) ?? appFile;
File('${Directory.current.path}/lib/app/view/app.dart')
File('${Directory.current.path}/${context.vars['app_directory']}/app.dart')
.writeAsStringSync(appFile);
} catch (e) {
context.logger.err('Could not implement go_router in app.dart,\nerror: $e');
Expand Down

0 comments on commit 10faac1

Please sign in to comment.