Skip to content

Commit d10cdf7

Browse files
authored
Merge pull request #693 from Flutterando/modular_5
feat!: Add New auto-dispose, selector and setArguments [Modular 5]
2 parents 768abce + e28a849 commit d10cdf7

File tree

393 files changed

+10885
-664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

393 files changed

+10885
-664
lines changed

doc/docs/flutter_modular/dependency-injection.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 4
2+
sidebar_position: 3
33
---
44

55
# Dependency Injection
@@ -174,7 +174,6 @@ run an instance destruction routine and are automatically removed from memory. H
174174

175175
- Stream/Sink (Dart Native).
176176
- ChangeNotifier/ValueNotifier (Flutter Native).
177-
- Store (Triple Pattern).
178177

179178
For registered objects that are not part of this list, we can implement a **Disposable** interface on the instance where we want to run an algorithm before dispose:
180179

@@ -189,9 +188,19 @@ class MyController implements Disposable {
189188
}
190189
```
191190

191+
The dispose of an instance can be set directly in `Bind` by implementing the `onDispose` property:
192+
193+
```dart
194+
@override
195+
final List<Bind> binds = [
196+
Bind.singleton((i) => MyBloc(), onDispose: (bloc) => bloc.close()),
197+
];
198+
```
199+
192200
:::tip TIP
193201

194-
As BLoC is based on Streams, the memory release takes effect automatically.
202+
There are pre-configured `Bind` for BLoC and Triple.
203+
See the packages [modular_bloc_bind](https://pub.dev/packages/modular_bloc_bind) and [modular_triple_bind](https://pub.dev/packages/modular_triple_bind)
195204

196205
:::
197206

doc/docs/flutter_modular/navegation.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ using square brackets notation (['parameter_name']).
113113
- *Query*: like the web environment, we can send parameters using query. This doesn't allows you to let the route dynamic, but it has the same effect when recovering a parameter;
114114

115115
```dart
116-
ChildRoute('/second', child: (context, args) => SecondPage(name: args.query['name'])),
116+
ChildRoute('/second', child: (context, args) => SecondPage(name: args.queryParams['name'])),
117117
```
118118

119-
Note that the route name is the same, so we can use **Modular.args.query** to get the parameter.
119+
Note that the route name is the same, so we can use **Modular.args.queryParams** to get the parameter.
120120
Let’s see how we can navigate using queries:
121-
121+
122122
```dart
123-
Modular.to.navigate('/second?name=jacob'); // args.query['name'] -> 'jacob'
124-
Modular.to.navigate('/second?name=sara'); // args.query['name'] -> 'sara'
125-
Modular.to.navigate('/second?name=rie'); // args.query['name'] -> 'rie'
123+
Modular.to.navigate('/second?name=jacob'); // args.queryParams['name'] -> 'jacob'
124+
Modular.to.navigate('/second?name=sara'); // args.queryParams['name'] -> 'sara'
125+
Modular.to.navigate('/second?name=rie'); // args.queryParams['name'] -> 'rie'
126126
```
127127

128128
:::tip TIP

doc/docs/flutter_modular/triple-integration.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

doc/docs/flutter_modular/watch.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 3
2+
sidebar_position: 4
33
---
44

55
# Watch
@@ -25,11 +25,7 @@ Used in `ChangeNotifier/ValueNotifier` classes and in RxNotifier.
2525

2626
- [Stream](https://api.dart.dev/stable/2.15.0/dart-async/Stream-class.html)
2727

28-
Used in StreamController or BLoC/Cubit
29-
30-
- [Store](https://triple.flutterando.com.br/docs/getting-started/using-flutter-triple)
31-
32-
Used in Triple Pattern in StreamStore and NotifierStore classes.
28+
Used in StreamController.
3329

3430
:::tip TIP
3531

@@ -70,3 +66,19 @@ class OnlyErrorWidget extends StatelessWidget {
7066
}
7167
```
7268

69+
It's also possible to configure a selector directly in bind:
70+
71+
```dart
72+
@override
73+
final List<Bind> binds = [
74+
//notifier return stream or listenable to use context.watch()
75+
Bind.singleton((i) => MyBloc(), selector: (bloc) => bloc.stream),
76+
];
77+
```
78+
79+
:::tip TIP
80+
81+
Existem `Bind` pré-configurados para BLoC e Triple.
82+
Veja os packages [modular_bloc_bind](https://pub.dev/packages/modular_bloc_bind) e [modular_triple_bind](https://pub.dev/packages/modular_triple_bind)
83+
84+
:::

flutter_modular/CHANGELOG.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
1+
## [5.0.0] - 2022-04-21
2+
- [BREAK CHANGE]: Removed `MaterialApp.modular()` and `Cupertino().modular()`.
3+
Use instead:
4+
```dart
5+
return MaterialApp.router(
6+
routeInformationParser: Modular.routeInformationParser,
7+
routerDelegate: Modular.routerDelegate,
8+
);
9+
10+
```
11+
This modification aims to keep Modular support independent of `WidgetApp` updates, and can be used in other bootstraps such as `FluentApp [fluent_ui]`.
12+
13+
- [BREAK CHANGE]: New auto-dispose configuration.
14+
Previously Modular had automatic closing or destruction calls for objects of type `ChangeNotifier/ValueNotifier`, `Stream` and Triple\`s `Stores`.
15+
Starting with version 5.0, Modular will provide the `Bind.onDispose` property for calls to destroy, close or dispose methods FOR EACH BIND. This will make the dispose settings more straightforward and less universal. Therefore, Modular will manage the destruction of Binds that implement `Disposable` only. This is the new configuration:
16+
```dart
17+
@override
18+
final List<Bind> binds = [
19+
Bind.singleton((i) => MyBloc(), onDispose: (bloc) => bloc.close()),
20+
];
21+
```
22+
The `Bind.onDispose` CANNOT be used in Bind type factory.
23+
You can choose to use `Bind.onDispose` or implement the `Disposable` class.
24+
25+
- Added `Bind.selector`. Generates a reactivity (Listenable/Stream) to be listened to when `context.watch()` is called.
26+
```dart
27+
@override
28+
final List<Bind> binds = [
29+
//notifier return stream or listenable to use context.watch()
30+
Bind.singleton((i) => MyBloc(), onDispose: (bloc) => bloc.close(), selector: (bloc) => bloc.stream),
31+
];
32+
```
33+
34+
- [BREAK CHANGE]: As already described above, the reactivities worked externally to Modular, providing a
35+
longer life to the project. For this reason, BLoC or Triple users should use special `Bind's` in order to use the `context.watch()` and auto dispose functionality. They are: `BlocBind()` and `TripleBind()`, which are available through external packages.
36+
[modular_bloc_bind](https://pub.dev/packages/modular_bloc_bind) -> BlocBind <br>
37+
[modular_triple_bind](https://pub.dev/packages/modular_triple_bind) -> TripleBind
38+
39+
Example:
40+
```dart
41+
42+
@override
43+
final List<Bind> binds = [
44+
BlocBind.singleton((i) => MyBloc()),
45+
];
46+
```
47+
48+
- [BREAK CHANGE] `Bind.export` works only after imported.
49+
- @deprecated `ModularState`.
50+
A few months of research showed us that ModularState caused unnecessary coupling with the view and made it difficult for those who used it to understand. For this reason, we decided to deprecate it to ensure code congruence for all professionals who use Modular.
51+
52+
- Removed `triple` dependency.
53+
- Simplify docs.
54+
- Added `Modular.setArguments`.
55+
```dart
56+
Modular.setArguments('cody1024d');
57+
58+
// get
59+
Modular.args.data; // -> cody1024d
60+
//or
61+
Bind((i) => MyClass(i.args.data));
62+
63+
```
64+
65+
### Issues
66+
67+
- Fix [#615](https://github.com/Flutterando/modular/issues/615)
68+
- Fix [#643](https://github.com/Flutterando/modular/issues/643)
69+
- Fix [#644](https://github.com/Flutterando/modular/issues/644)
70+
- Fix [#666](https://github.com/Flutterando/modular/issues/666)
71+
- Fix [#668](https://github.com/Flutterando/modular/issues/668)
72+
- Fix [#681](https://github.com/Flutterando/modular/issues/681)
73+
- Fix [#694](https://github.com/Flutterando/modular/issues/694)
74+
175
## [4.5.1+1] - 2022-04-05
276
- Fixed `modular_core` and resolve issues [#699] [#671] [#678].
377

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at
17+
# https://dart-lang.github.io/linter/lints/index.html.
18+
#
19+
# Instead of disabling a lint rule for the entire project in the
20+
# section below, it can also be suppressed for a single line of code
21+
# or a specific dart file by using the `// ignore: name_of_lint` and
22+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# producing the lint.
24+
rules:
25+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27+
28+
# Additional information about this file can be found at
29+
# https://dart.dev/guides/language/analysis-options

flutter_modular/example/android/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ GeneratedPluginRegistrant.java
99
# Remember to never publicly share your keystore.
1010
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
1111
key.properties
12+
**/*.keystore
13+
**/*.jks

flutter_modular/example/android/.project

Lines changed: 0 additions & 28 deletions
This file was deleted.

flutter_modular/example/android/.settings/org.eclipse.buildship.core.prefs

Lines changed: 0 additions & 13 deletions
This file was deleted.

flutter_modular/example/android/app/build.gradle

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,26 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 30
29+
compileSdkVersion flutter.compileSdkVersion
30+
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
36+
kotlinOptions {
37+
jvmTarget = '1.8'
38+
}
3039

3140
sourceSets {
3241
main.java.srcDirs += 'src/main/kotlin'
3342
}
3443

3544
defaultConfig {
3645
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
37-
applicationId "com.example.search"
38-
minSdkVersion 16
39-
targetSdkVersion 30
46+
applicationId "com.example.example"
47+
minSdkVersion flutter.minSdkVersion
48+
targetSdkVersion flutter.targetSdkVersion
4049
versionCode flutterVersionCode.toInteger()
4150
versionName flutterVersionName
4251
}

flutter_modular/example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.search">
2+
package="com.example.example">
33
<!-- Flutter needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->

flutter_modular/example/android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.search">
2+
package="com.example.example">
33
<application
4-
android:label="search"
4+
android:label="example"
5+
android:name="${applicationName}"
56
android:icon="@mipmap/ic_launcher">
67
<activity
78
android:name=".MainActivity"
9+
android:exported="true"
810
android:launchMode="singleTop"
911
android:theme="@style/LaunchTheme"
1012
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
@@ -18,15 +20,6 @@
1820
android:name="io.flutter.embedding.android.NormalTheme"
1921
android:resource="@style/NormalTheme"
2022
/>
21-
<!-- Displays an Android View that continues showing the launch screen
22-
Drawable until Flutter paints its first frame, then this splash
23-
screen fades out. A splash screen is useful to avoid any visual
24-
gap between the end of Android's launch screen and the painting of
25-
Flutter's first frame. -->
26-
<meta-data
27-
android:name="io.flutter.embedding.android.SplashScreenDrawable"
28-
android:resource="@drawable/launch_background"
29-
/>
3023
<intent-filter>
3124
<action android:name="android.intent.action.MAIN"/>
3225
<category android:name="android.intent.category.LAUNCHER"/>

flutter_modular/example/android/app/src/main/res/values-night/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
This theme determines the color of the Android Window while your
1111
Flutter UI initializes, as well as behind your Flutter UI while its
1212
running.
13-
13+
1414
This Theme is only used starting with V2 of Flutter's Android embedding. -->
1515
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
1616
<item name="android:windowBackground">?android:colorBackground</item>

flutter_modular/example/android/app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
This theme determines the color of the Android Window while your
1111
Flutter UI initializes, as well as behind your Flutter UI while its
1212
running.
13-
13+
1414
This Theme is only used starting with V2 of Flutter's Android embedding. -->
1515
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
1616
<item name="android:windowBackground">?android:colorBackground</item>

flutter_modular/example/android/app/src/profile/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.search">
2+
package="com.example.example">
33
<!-- Flutter needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->

0 commit comments

Comments
 (0)