File tree Expand file tree Collapse file tree 9 files changed +23
-15
lines changed Expand file tree Collapse file tree 9 files changed +23
-15
lines changed Original file line number Diff line number Diff line change
1
+ ## 0.0.6
2
+ * ** break** : remove ` initialData ` and ` emptyWidget ` from ` StateStream ` collector
3
+ * add automatically emit of initial value to ` StateStream `
4
+
1
5
## 0.0.5
2
6
* remove stream from ActionNotifier in favor of extension type ` ActionStream `
3
7
* remove stream from StateNotifier in favor of extension type ` StateStream `
Original file line number Diff line number Diff line change @@ -63,7 +63,6 @@ class _MainAppState extends State<MainApp> {
63
63
// Collect the data from the stream
64
64
// and build a widget based on its data
65
65
counter.countStream.collectAsWidget(
66
- initialData: 0,
67
66
(value) {
68
67
return Text('Count: $value');
69
68
},
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import 'package:view_model_macro/view_model_macro.dart';
4
4
class Calculator {
5
5
Calculator () {
6
6
countStream.collect ((countValue) {
7
- if (countValue % 3 == 0 ) {
7
+ if (countValue % 3 == 0 && countValue > 0 ) {
8
8
_dispatchShowSnackBar ();
9
9
}
10
10
});
Original file line number Diff line number Diff line change @@ -43,7 +43,6 @@ class _MainAppState extends State<MainApp> {
43
43
mainAxisSize: MainAxisSize .min,
44
44
children: [
45
45
counter.countStream.collectAsWidget (
46
- initialData: 0 ,
47
46
(value) {
48
47
return Text ('Count: $value ' );
49
48
},
Original file line number Diff line number Diff line change @@ -144,6 +144,14 @@ packages:
144
144
url: "https://pub.dev"
145
145
source: hosted
146
146
version: "1.9.0"
147
+ rxdart:
148
+ dependency: transitive
149
+ description:
150
+ name: rxdart
151
+ sha256: "5c3004a4a8dbb94bd4bf5412a4def4acdaa12e12f269737a5751369e12d1a962"
152
+ url: "https://pub.dev"
153
+ source: hosted
154
+ version: "0.28.0"
147
155
sky_engine:
148
156
dependency: transitive
149
157
description: flutter
@@ -211,7 +219,7 @@ packages:
211
219
path: ".."
212
220
relative: true
213
221
source: path
214
- version: "0.0.4 "
222
+ version: "0.0.5 "
215
223
vm_service:
216
224
dependency: transitive
217
225
description:
Original file line number Diff line number Diff line change @@ -7,19 +7,14 @@ import 'package:view_model_macro/src/widgets/stream_listener.dart';
7
7
/// Extension methods for collecting data from [StateStream] s.
8
8
extension StateStreamCollectorX <T > on StateStream <T > {
9
9
/// Collects the data from the stream to build a widget based on its data.
10
- Widget collectAsWidget (
11
- Widget Function (T ) builder, {
12
- Widget ? emptyData,
13
- T ? initialData,
14
- }) {
10
+ Widget collectAsWidget (Widget Function (T ) builder) {
15
11
return StreamBuilder (
16
12
stream: stream,
17
- initialData: initialData,
18
13
builder: (context, snapshot) {
19
14
if (snapshot.hasData) {
20
15
return builder (snapshot.data as T );
21
16
} else {
22
- return emptyData ?? const SizedBox .shrink ();
17
+ return const SizedBox .shrink ();
23
18
}
24
19
},
25
20
);
Original file line number Diff line number Diff line change @@ -16,9 +16,10 @@ import 'package:meta/meta.dart';
16
16
/// {@endtemplate}
17
17
abstract class Notifier <T > {
18
18
/// {@macro Notifier}
19
- Notifier ();
19
+ Notifier ([StreamController <T >? controller]):
20
+ _controller = controller ?? StreamController <T >.broadcast ();
20
21
21
- final StreamController <T > _controller = StreamController < T >. broadcast () ;
22
+ final StreamController <T > _controller;
22
23
final List <StreamSubscription <T >> _subscriptions = [];
23
24
24
25
/// Notifies all listeners with the new value.
Original file line number Diff line number Diff line change 1
1
import 'dart:async' ;
2
2
3
+ import 'package:rxdart/rxdart.dart' ;
3
4
import 'package:view_model_macro/src/notifiers/notifier.dart' ;
4
5
5
6
/// The type wrapper for [Stream] s emitted by a [StateNotifier] .
@@ -19,7 +20,7 @@ extension type StateStream<T>(Stream<T> stream) {}
19
20
/// {@endtemplate}
20
21
class StateNotifier <T > extends Notifier <T > {
21
22
/// {@macro StateNotifier}
22
- StateNotifier (this ._state);
23
+ StateNotifier (this ._state) : super ( BehaviorSubject < T >. seeded (_state)) ;
23
24
24
25
T _state;
25
26
Original file line number Diff line number Diff line change 1
1
name : view_model_macro
2
2
description : " Experimental support for ViewModel classes in Dart using pckg:macros."
3
- version : 0.0.5
3
+ version : 0.0.6
4
4
repository : https://github.com/alvarobcprado/view_model_macro
5
5
topics : [macros, view-model]
6
6
@@ -13,6 +13,7 @@ dependencies:
13
13
sdk : flutter
14
14
macros : ^0.1.0-main.5
15
15
meta : ^1.15.0
16
+ rxdart : ^0.28.0
16
17
17
18
dev_dependencies :
18
19
flutter_test :
You can’t perform that action at this time.
0 commit comments