Skip to content

Commit

Permalink
Review exmaple.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Nov 22, 2018
1 parent 8f0bc08 commit 4623707
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 155 deletions.
240 changes: 113 additions & 127 deletions bloc_login_example/.idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bloc_login_example/lib/blocs/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AuthBloc extends Object {

AuthBloc() {
loggedIn.listen((bool result) {
print('loggedIn: $result');
if (_context != null) {
Navigator.pushReplacement(
_context,
Expand Down
1 change: 1 addition & 0 deletions bloc_login_example/lib/blocs/sample_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SampleBloc extends Object {

SampleBloc() {
init();
setMessage('test');
}

init() {
Expand Down
42 changes: 20 additions & 22 deletions bloc_login_example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import 'package:flutter/material.dart';

import 'blocs/bloc_provider.dart' show BlocProvider;
import 'screens/auth.dart' show Auth;
import 'screens/review.dart' show Review;
import 'package:bloc_login_example/blocs/bloc_provider.dart' show BlocProvider;
import 'package:bloc_login_example/screens/auth.dart' show Auth;
import 'package:bloc_login_example/screens/review.dart' show Review;

void main() => runApp(new MyApp());
void main() => runApp(BlocProvider(child: new MyApp()));

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return BlocProvider(
child: MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
home: Auth(),
routes: {
'/review': (BuildContext context) => Review(),
}
return MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
home: Auth(),
routes: {
'/review': (BuildContext context) => Review(),
}
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion bloc_login_example/lib/screens/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _AuthState extends State<Auth> {
Future.delayed(Duration.zero, () async {
BlocProvider.of(context).authBloc.setContext(context);
await Future.delayed(Duration(seconds: 3));
BlocProvider.of(context).authBloc.setLoggedIn(true);
BlocProvider.of(context).authBloc.setLoggedIn(false);
});
}
}
2 changes: 1 addition & 1 deletion bloc_login_example/lib/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _LoginState extends State<Login> {
Row(children: <Widget>[
Expanded(child:
Btn(
text: 'SIGN UP',
text: 'REVIEW',
onPress: () => Navigator.of(context).pushNamed('/review'),
height: 60.0,
fontSize: 16.0,
Expand Down
31 changes: 27 additions & 4 deletions bloc_login_example/lib/screens/review.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'dart:async';
import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../blocs/review_bloc.dart';
import 'package:bloc_login_example/blocs/review_bloc.dart';
import 'package:bloc_login_example/blocs/bloc_provider.dart';

class Review extends StatefulWidget {
@override
Expand All @@ -11,20 +12,42 @@ class Review extends StatefulWidget {

class _State extends State<Review> {
ReviewBloc reviewBloc = ReviewBloc();
var _stream;

@override
void initState() {
super.initState();
_stream = StreamZip([
reviewBloc.userId, reviewBloc.message,
]);
// _stream = StreamGroup.merge([reviewBloc.userId, reviewBloc.message]);
}

@override
Widget build(BuildContext context) {
var bloc = BlocProvider.of(context);
return StreamBuilder(
stream: StreamZip([
reviewBloc.userId, reviewBloc.message,
]),
stream: _stream,
builder: (context, snapshot) {
print('snapshot');
print(snapshot);
return Container(
width: 200.0,
color: Colors.white,
child: Column(
children: <Widget>[
Text('myUserId: ${snapshot.data[0]}'),
Text('message: ${snapshot.data[1]}'),
],
),
);
},
);
}

@override
void dispose() {
reviewBloc.dispose();
super.dispose();
}
}

0 comments on commit 4623707

Please sign in to comment.