Skip to content

Commit 4623707

Browse files
committed
Review exmaple.
1 parent 8f0bc08 commit 4623707

File tree

7 files changed

+164
-155
lines changed

7 files changed

+164
-155
lines changed

bloc_login_example/.idea/workspace.xml

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

bloc_login_example/lib/blocs/auth_bloc.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AuthBloc extends Object {
2121

2222
AuthBloc() {
2323
loggedIn.listen((bool result) {
24+
print('loggedIn: $result');
2425
if (_context != null) {
2526
Navigator.pushReplacement(
2627
_context,

bloc_login_example/lib/blocs/sample_bloc.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class SampleBloc extends Object {
99

1010
SampleBloc() {
1111
init();
12+
setMessage('test');
1213
}
1314

1415
init() {

bloc_login_example/lib/main.dart

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
import 'package:flutter/material.dart';
22

3-
import 'blocs/bloc_provider.dart' show BlocProvider;
4-
import 'screens/auth.dart' show Auth;
5-
import 'screens/review.dart' show Review;
3+
import 'package:bloc_login_example/blocs/bloc_provider.dart' show BlocProvider;
4+
import 'package:bloc_login_example/screens/auth.dart' show Auth;
5+
import 'package:bloc_login_example/screens/review.dart' show Review;
66

7-
void main() => runApp(new MyApp());
7+
void main() => runApp(BlocProvider(child: new MyApp()));
88

99
class MyApp extends StatelessWidget {
1010
// This widget is the root of your application.
1111
@override
1212
Widget build(BuildContext context) {
13-
return BlocProvider(
14-
child: MaterialApp(
15-
title: 'Flutter Demo',
16-
theme: new ThemeData(
17-
// This is the theme of your application.
18-
//
19-
// Try running your application with "flutter run". You'll see the
20-
// application has a blue toolbar. Then, without quitting the app, try
21-
// changing the primarySwatch below to Colors.green and then invoke
22-
// "hot reload" (press "r" in the console where you ran "flutter run",
23-
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
24-
// counter didn't reset back to zero; the application is not restarted.
25-
primarySwatch: Colors.blue,
26-
),
27-
home: Auth(),
28-
routes: {
29-
'/review': (BuildContext context) => Review(),
30-
}
13+
return MaterialApp(
14+
title: 'Flutter Demo',
15+
theme: new ThemeData(
16+
// This is the theme of your application.
17+
//
18+
// Try running your application with "flutter run". You'll see the
19+
// application has a blue toolbar. Then, without quitting the app, try
20+
// changing the primarySwatch below to Colors.green and then invoke
21+
// "hot reload" (press "r" in the console where you ran "flutter run",
22+
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
23+
// counter didn't reset back to zero; the application is not restarted.
24+
primarySwatch: Colors.blue,
3125
),
26+
home: Auth(),
27+
routes: {
28+
'/review': (BuildContext context) => Review(),
29+
}
3230
);
3331
}
3432
}

bloc_login_example/lib/screens/auth.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class _AuthState extends State<Auth> {
6161
Future.delayed(Duration.zero, () async {
6262
BlocProvider.of(context).authBloc.setContext(context);
6363
await Future.delayed(Duration(seconds: 3));
64-
BlocProvider.of(context).authBloc.setLoggedIn(true);
64+
BlocProvider.of(context).authBloc.setLoggedIn(false);
6565
});
6666
}
6767
}

bloc_login_example/lib/screens/login.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class _LoginState extends State<Login> {
112112
Row(children: <Widget>[
113113
Expanded(child:
114114
Btn(
115-
text: 'SIGN UP',
115+
text: 'REVIEW',
116116
onPress: () => Navigator.of(context).pushNamed('/review'),
117117
height: 60.0,
118118
fontSize: 16.0,

bloc_login_example/lib/screens/review.dart

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import 'dart:async';
22
import 'package:async/async.dart';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
5-
import '../blocs/review_bloc.dart';
5+
import 'package:bloc_login_example/blocs/review_bloc.dart';
6+
import 'package:bloc_login_example/blocs/bloc_provider.dart';
67

78
class Review extends StatefulWidget {
89
@override
@@ -11,20 +12,42 @@ class Review extends StatefulWidget {
1112

1213
class _State extends State<Review> {
1314
ReviewBloc reviewBloc = ReviewBloc();
15+
var _stream;
16+
17+
@override
18+
void initState() {
19+
super.initState();
20+
_stream = StreamZip([
21+
reviewBloc.userId, reviewBloc.message,
22+
]);
23+
// _stream = StreamGroup.merge([reviewBloc.userId, reviewBloc.message]);
24+
}
25+
1426
@override
1527
Widget build(BuildContext context) {
28+
var bloc = BlocProvider.of(context);
1629
return StreamBuilder(
17-
stream: StreamZip([
18-
reviewBloc.userId, reviewBloc.message,
19-
]),
30+
stream: _stream,
2031
builder: (context, snapshot) {
2132
print('snapshot');
2233
print(snapshot);
2334
return Container(
2435
width: 200.0,
2536
color: Colors.white,
37+
child: Column(
38+
children: <Widget>[
39+
Text('myUserId: ${snapshot.data[0]}'),
40+
Text('message: ${snapshot.data[1]}'),
41+
],
42+
),
2643
);
2744
},
2845
);
2946
}
47+
48+
@override
49+
void dispose() {
50+
reviewBloc.dispose();
51+
super.dispose();
52+
}
3053
}

0 commit comments

Comments
 (0)