Skip to content

Commit 16876af

Browse files
authored
feat: optimize code generation and update bricks (#199)
1 parent 272267f commit 16876af

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ You can do that by executing `flutter pub run flutter_native_splash:create`.
8585
Although you can setup a bunch of features in this library, it doesn't provide a way to display animations.
8686
If you need a more personalized splash screen, you can edit the native code or just remove this library.
8787

88+
### Code generation
89+
90+
Code generation is created using `build_runner` package.\
91+
To configure this package edit the `build.yaml`\
92+
To add new files to watch for code generation add the following lines:
93+
```
94+
targets:
95+
$default:
96+
builders:
97+
# Previous configured builders
98+
...
99+
builder_package_name:
100+
generate_for:
101+
# Example glob for only the Dart files under `lib/models`
102+
- lib/models/*.dart
103+
```
104+
To create generated code run `clean_up.sh` under [scripts] folder or the following command: `flutter pub run build_runner build --delete-conflicting-outputs`
105+
88106
### Pre Push config
89107

90108
In order to setup pre-push hook you need to go to the root of the project and run `git config core.hooksPath .github/hooks`
@@ -102,3 +120,4 @@ In order to setup pre-push hook you need to go to the root of the project and ru
102120
[repository_folder]: https://github.com/xmartlabs/flutter-template/tree/main/lib/core/repository
103121
[data_source_folder]: https://github.com/xmartlabs/flutter-template/tree/main/lib/core/source
104122
[get_it]: https://pub.dev/packages/get_it
123+
[scripts]: https://github.com/xmartlabs/flutter-template/tree/main/scripts

bricks/xl_cubit_screen/__brick__/{{name.snakeCase()}}/{{name.snakeCase()}}_cubit.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:bloc/bloc.dart';
1+
import 'package:flutter_bloc/flutter_bloc.dart';
22
import 'package:freezed_annotation/freezed_annotation.dart';
33

44
part '{{name.snakeCase()}}_state.dart';

bricks/xl_cubit_screen/__brick__/{{name.snakeCase()}}/{{name.snakeCase()}}_screen.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '{{name.snakeCase()}}_cubit.dart';
66

77
@RoutePage()
88
class {{name.pascalCase()}}Screen extends StatelessWidget {
9-
const {{name.pascalCase()}}Screen({Key? key}) : super(key: key);
9+
const {{name.pascalCase()}}Screen({super.key});
1010

1111
@override
1212
Widget build(BuildContext context) => BlocProvider(

build.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,21 @@ targets:
55
options:
66
explicit_to_json: true
77
field_rename: snake
8+
generate_for:
9+
include:
10+
- lib/core/model/*.dart
11+
- lib/core/model/service/*.dart
12+
freezed:
13+
generate_for:
14+
include:
15+
- lib/core/model/*.dart
16+
- lib/core/common/network_exceptions.dart
17+
- lib/core/model/service/*.dart
18+
- "lib/ui/**_cubit.dart"
19+
- lib/ui/section/error_handler/general_error.dart
20+
auto_route_generator:
21+
generate_for:
22+
include:
23+
- "lib/ui/**_router.dart"
24+
- "lib/ui/**_screen.dart"
25+
- "lib/ui/**_section.dart"

0 commit comments

Comments
 (0)