Skip to content

Commit

Permalink
Putting transition between routing.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Nov 18, 2018
1 parent 55425d5 commit 744577b
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 62 deletions.
169 changes: 128 additions & 41 deletions bloc_login_example/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions bloc_login_example/lib/blocs/auth_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import 'dart:async';
import 'package:flutter/material.dart';

import '../screens/login.dart';
import '../screens/sample.dart';

enum Gender {
male, female
}

class AuthBloc extends Object {
BuildContext _context;
final _loggedIn = StreamController<bool>.broadcast();
final _doneLoading = StreamController<bool>.broadcast();

Expand All @@ -15,13 +20,37 @@ class AuthBloc extends Object {
Function(bool) get setLoading => _doneLoading.sink.add;

AuthBloc() {
init();
loggedIn.listen((bool result) {
if (_context != null) {
Navigator.pushReplacement(
_context,
PageRouteBuilder(
pageBuilder: (_context1, animation1, animation2) {
return !result ? Login() : Sample();
},
transitionsBuilder: (_context, animation, _, child) {
return new SlideTransition(
child: child,
position: new Tween<Offset>(
begin: !result ? const Offset(-1.0, 0.0) : const Offset(1.0, 0.0),
end: Offset.zero,
).animate(animation),
);
},
transitionDuration: Duration(milliseconds: 500),
),
);
}
}, onError: (error) {
Scaffold.of(_context).showSnackBar(new SnackBar(
content: new Text(error.message),
));
});
setLoading(true);
}

init() async {
print('init');
await Future.delayed(Duration(seconds: 2));
setLoading(true);
setContext(BuildContext context) {
_context = context;
}

dispose() {
Expand Down
Loading

0 comments on commit 744577b

Please sign in to comment.