AppFlowy/app_flowy/lib/welcome/infrastructure/interface_impl.dart

59 lines
2.0 KiB
Dart
Raw Normal View History

2021-07-12 15:27:58 +00:00
import 'package:app_flowy/home/application/edit_pannel/edit_pannel_bloc.dart';
import 'package:app_flowy/home/application/home_bloc.dart';
import 'package:app_flowy/home/application/menu/menu_bloc.dart';
import 'package:app_flowy/home/application/watcher/home_watcher_bloc.dart';
import 'package:app_flowy/home/presentation/home_screen.dart';
2021-07-13 05:14:49 +00:00
import 'package:app_flowy/user/presentation/sign_in/sign_in_screen.dart';
2021-07-12 15:27:58 +00:00
import 'package:app_flowy/welcome/application/welcome_bloc.dart';
import 'package:app_flowy/welcome/domain/auth_state.dart';
import 'package:app_flowy/welcome/domain/interface.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/protobuf/user_detail.pb.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart';
2021-07-13 05:14:49 +00:00
class WelcomeDepsResolver {
static Future<void> resolve(GetIt getIt) async {
2021-07-12 15:27:58 +00:00
getIt.registerFactory<IWelcomeAuth>(() => WelcomeAuthImpl());
getIt.registerFactory<IWelcomeRoute>(() => WelcomeRoute());
getIt.registerFactory<HomeBloc>(() => HomeBloc());
getIt.registerFactory<HomeWatcherBloc>(() => HomeWatcherBloc());
getIt.registerFactory<EditPannelBloc>(() => EditPannelBloc());
getIt.registerFactory<MenuBloc>(() => MenuBloc());
getIt
.registerFactory<WelcomeBloc>(() => WelcomeBloc(getIt<IWelcomeAuth>()));
}
}
class WelcomeAuthImpl implements IWelcomeAuth {
@override
Future<AuthState> currentUserState() {
final result = UserEventGetStatus().send();
return result.then((result) {
return result.fold(
(userDetail) {
return AuthState.authenticated(userDetail);
},
(userError) {
return AuthState.unauthenticated(userError);
},
);
});
}
}
class WelcomeRoute implements IWelcomeRoute {
@override
Widget pushHomeScreen(UserDetail user) {
return HomeScreen(user);
}
@override
Widget pushSignInScreen() {
2021-07-13 05:14:49 +00:00
return const SignInScreen();
2021-07-12 15:27:58 +00:00
}
}