Skip to content

Commit

Permalink
update examples/flutter_login to make UserRepository injectable
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Jan 2, 2019
1 parent ee87e01 commit 62c9b6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docs/logintutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -806,16 +806,21 @@ import 'package:flutter_login/common/common.dart';
void main() => runApp(App());
class App extends StatefulWidget {
final UserRepository userRepository;
App({Key key, this.userRepository}) : super(key: key);
@override
State<App> createState() => AppState();
}
class AppState extends State<App> {
final UserRepository _userRepository = UserRepository();
UserRepository _userRepository;
AuthenticationBloc _authenticationBloc;
@override
void initState() {
_userRepository = widget.userRepository ?? UserRepository();
_authenticationBloc = AuthenticationBloc(userRepository: _userRepository);
_authenticationBloc.dispatch(AppStart());
super.initState();
Expand Down
7 changes: 6 additions & 1 deletion examples/flutter_login/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ void main() {
}

class App extends StatefulWidget {
final UserRepository userRepository;

App({Key key, this.userRepository}) : super(key: key);

@override
State<App> createState() => AppState();
}

class AppState extends State<App> {
AuthenticationBloc _authenticationBloc;
final UserRepository _userRepository = UserRepository();
UserRepository _userRepository;

@override
void initState() {
_userRepository = widget.userRepository ?? UserRepository();
_authenticationBloc = AuthenticationBloc(userRepository: _userRepository);
_authenticationBloc.dispatch(AppStart());
super.initState();
Expand Down

0 comments on commit 62c9b6b

Please sign in to comment.