Skip to content

Commit 88a63f2

Browse files
authored
Merge pull request #13 from Flutteror/master
[example/bloc_demo]fix initalData to _count
2 parents 7114894 + 5df3d13 commit 88a63f2

File tree

14 files changed

+491
-506
lines changed

14 files changed

+491
-506
lines changed

mecury_project/example/bloc_demo/.idea/libraries/Dart_Packages.xml

Lines changed: 118 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mecury_project/example/bloc_demo/.idea/libraries/Dart_SDK.xml

Lines changed: 19 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mecury_project/example/bloc_demo/.idea/workspace.xml

Lines changed: 246 additions & 283 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildSystemType</key>
6+
<string>Original</string>
7+
</dict>
8+
</plist>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import 'package:rxdart/rxdart.dart';
22
import 'dart:async';
33

4-
class CountBLoC{
5-
6-
int _count= 0;
4+
class CountBLoC {
5+
int _count = 0;
76
var _subject = BehaviorSubject<int>();
87

9-
Stream<int> get value => _subject.stream;
8+
Stream<int> get stream => _subject.stream;
9+
int get value => _count;
1010

11-
void increment()=> _subject.add(++_count);
11+
void increment() => _subject.add(++_count);
1212

13-
void dispose(){
13+
void dispose() {
1414
_subject.close();
1515
}
16-
}
16+
}

mecury_project/example/bloc_demo/lib/rxdart/top_page.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class TopPage extends StatelessWidget {
1313
),
1414
body: Center(
1515
child: StreamBuilder<int>(
16-
stream: bloc.value,
17-
initialData: 0,
16+
stream: bloc.stream,
17+
initialData: bloc.value,
1818
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
1919
return Text(
2020
'You hit me: ${snapshot.data} times',
@@ -24,9 +24,8 @@ class TopPage extends StatelessWidget {
2424
),
2525
floatingActionButton: FloatingActionButton(
2626
child: Icon(Icons.navigate_next),
27-
onPressed: () => Navigator.of(context)
28-
.push(MaterialPageRoute(builder: (context) => UnderPage()))),
27+
onPressed: () =>
28+
Navigator.of(context).push(MaterialPageRoute(builder: (context) => UnderPage()))),
2929
);
3030
}
3131
}
32-

mecury_project/example/bloc_demo/lib/rxdart/under_page.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ class UnderPage extends StatelessWidget {
1212
),
1313
body: Center(
1414
child: StreamBuilder(
15-
stream: bloc.value,
16-
initialData: 0,
15+
stream: bloc.stream,
16+
initialData: bloc.value,
1717
builder: (context, snapshot) => Text(
18-
"You hit me: ${snapshot.data} times",
19-
style: Theme.of(context).textTheme.display1,
20-
)),
18+
"You hit me: ${snapshot.data} times",
19+
style: Theme.of(context).textTheme.display1,
20+
)),
2121
),
2222
floatingActionButton: FloatingActionButton(
23-
onPressed: ()=> bloc.increment(),
23+
onPressed: () => bloc.increment(),
2424
child: Icon(Icons.add),
2525
),
2626
);
2727
}
2828
}
29-
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'dart:async';
22

33
class CountBLoC {
4-
54
int _count = 0;
65
var _countController = StreamController.broadcast<int>();
76

8-
Stream<int> get value => _countController.stream;
7+
Stream<int> get stream => _subject.stream;
8+
int get value => _count;
99

1010
increment() {
1111
_countController.sink.add(++_count);
@@ -15,4 +15,3 @@ class CountBLoC {
1515
_countController.close();
1616
}
1717
}
18-

mecury_project/example/bloc_demo/lib/scoped/top_page.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class TopPage extends StatelessWidget {
1313
),
1414
body: Center(
1515
child: StreamBuilder<int>(
16-
stream: bloc.value,
17-
initialData: 0,
16+
stream: bloc.stream,
17+
initialData: bloc.value,
1818
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
1919
return Text(
2020
'You hit me: ${snapshot.data} times',
@@ -24,9 +24,8 @@ class TopPage extends StatelessWidget {
2424
),
2525
floatingActionButton: FloatingActionButton(
2626
child: Icon(Icons.navigate_next),
27-
onPressed: () => Navigator.of(context)
28-
.push(MaterialPageRoute(builder: (context) => UnderPage()))),
27+
onPressed: () =>
28+
Navigator.of(context).push(MaterialPageRoute(builder: (context) => UnderPage()))),
2929
);
3030
}
3131
}
32-

mecury_project/example/bloc_demo/lib/scoped/under_page.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ class UnderPage extends StatelessWidget {
1212
),
1313
body: Center(
1414
child: StreamBuilder(
15-
stream: bloc.value,
16-
initialData: 0,
15+
stream: bloc.stream,
16+
initialData: bloc.value,
1717
builder: (context, snapshot) => Text(
18-
"You hit me: ${snapshot.data} times",
19-
style: Theme.of(context).textTheme.display1,
20-
)),
18+
"You hit me: ${snapshot.data} times",
19+
style: Theme.of(context).textTheme.display1,
20+
)),
2121
),
2222
floatingActionButton: FloatingActionButton(
23-
onPressed: ()=> bloc.increment(),
23+
onPressed: () => bloc.increment(),
2424
child: Icon(Icons.add),
2525
),
2626
);
2727
}
2828
}
29-

mecury_project/example/bloc_demo/lib/single_global_instance/blocs/count_bloc.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'dart:async';
22

33
class CountBLoC {
4-
54
int _count = 0;
65
var _countController = StreamController.broadcast<int>();
76

8-
Stream<int> get value => _countController.stream;
7+
Stream<int> get stream => _subject.stream;
8+
int get value => _count;
99

1010
increment() {
1111
_countController.sink.add(++_count);

mecury_project/example/bloc_demo/lib/single_global_instance/top_page.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class TopPage extends StatelessWidget {
1111
),
1212
body: Center(
1313
child: StreamBuilder<int>(
14-
stream: bLoC.value,
15-
initialData: 0,
14+
stream: bloc.stream,
15+
initialData: bloc.value,
1616
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
1717
return Text(
1818
'You hit me: ${snapshot.data} times',
@@ -21,10 +21,8 @@ class TopPage extends StatelessWidget {
2121
),
2222
floatingActionButton: FloatingActionButton(
2323
child: Icon(Icons.add),
24-
onPressed: () => Navigator.of(context)
25-
.push(MaterialPageRoute(builder: (context) => UnderPage()))),
24+
onPressed: () =>
25+
Navigator.of(context).push(MaterialPageRoute(builder: (context) => UnderPage()))),
2626
);
2727
}
2828
}
29-
30-

mecury_project/example/bloc_demo/lib/single_global_instance/under_page.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@ import 'blocs/count_bloc.dart';
44
class UnderPage extends StatelessWidget {
55
@override
66
Widget build(BuildContext context) {
7-
87
return Scaffold(
98
appBar: AppBar(
109
title: Text('Under Page'),
1110
),
1211
body: Center(
1312
child: StreamBuilder(
14-
stream: bLoC.value,
15-
initialData: 0,
13+
stream: bloc.stream,
14+
initialData: bloc.value,
1615
builder: (context, snapshot) => Text(
17-
"You hit me: ${snapshot.data} times",
18-
style: Theme.of(context).textTheme.display1,
19-
)),
16+
"You hit me: ${snapshot.data} times",
17+
style: Theme.of(context).textTheme.display1,
18+
)),
2019
),
2120
floatingActionButton: FloatingActionButton(
22-
onPressed: ()=> bLoC.increment(),
21+
onPressed: () => bLoC.increment(),
2322
child: Icon(Icons.add),
2423
),
2524
);
2625
}
2726
}
28-

0 commit comments

Comments
 (0)