[flutter]: merge welcome to user && refactor abstract class with class with freezed objects

This commit is contained in:
appflowy 2021-10-09 10:09:31 +08:00
parent f62afcb436
commit d46e5aa0b9
23 changed files with 51 additions and 59 deletions

View file

@ -1,5 +1,5 @@
import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/welcome/presentation/splash_screen.dart'; import 'package:app_flowy/user/presentation/splash_screen.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class FlowyApp implements EntryPoint { class FlowyApp implements EntryPoint {

View file

@ -2,7 +2,6 @@ import 'package:app_flowy/workspace/infrastructure/deps_resolver.dart';
import 'package:app_flowy/startup/launch.dart'; import 'package:app_flowy/startup/launch.dart';
import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/user/infrastructure/deps_resolver.dart'; import 'package:app_flowy/user/infrastructure/deps_resolver.dart';
import 'package:app_flowy/welcome/infrastructure/deps_resolver.dart';
import 'package:flowy_sdk/flowy_sdk.dart'; import 'package:flowy_sdk/flowy_sdk.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
@ -16,6 +15,5 @@ Future<void> initGetIt(
getIt.registerLazySingleton<AppLauncher>(() => AppLauncher(env, getIt)); getIt.registerLazySingleton<AppLauncher>(() => AppLauncher(env, getIt));
await UserDepsResolver.resolve(getIt); await UserDepsResolver.resolve(getIt);
await WelcomeDepsResolver.resolve(getIt);
await HomeDepsResolver.resolve(getIt); await HomeDepsResolver.resolve(getIt);
} }

View file

@ -97,7 +97,7 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
} }
@freezed @freezed
abstract class SignUpEvent with _$SignUpEvent { class SignUpEvent with _$SignUpEvent {
const factory SignUpEvent.signUpWithUserEmailAndPassword() = const factory SignUpEvent.signUpWithUserEmailAndPassword() =
SignUpWithUserEmailAndPassword; SignUpWithUserEmailAndPassword;
const factory SignUpEvent.emailChanged(String email) = EmailChanged; const factory SignUpEvent.emailChanged(String email) = EmailChanged;
@ -107,7 +107,7 @@ abstract class SignUpEvent with _$SignUpEvent {
} }
@freezed @freezed
abstract class SignUpState with _$SignUpState { class SignUpState with _$SignUpState {
const factory SignUpState({ const factory SignUpState({
String? email, String? email,
String? password, String? password,

View file

@ -1,5 +1,5 @@
import 'package:app_flowy/welcome/domain/auth_state.dart'; import 'package:app_flowy/user/domain/auth_state.dart';
import 'package:app_flowy/welcome/domain/i_splash.dart'; import 'package:app_flowy/user/domain/i_splash.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
@ -21,12 +21,12 @@ class SplashBloc extends Bloc<SplashEvent, SplashState> {
} }
@freezed @freezed
abstract class SplashEvent with _$SplashEvent { class SplashEvent with _$SplashEvent {
const factory SplashEvent.getUser() = _GetUser; const factory SplashEvent.getUser() = _GetUser;
} }
@freezed @freezed
abstract class SplashState implements _$SplashState { class SplashState with _$SplashState {
const factory SplashState({ const factory SplashState({
required AuthState auth, required AuthState auth,
}) = _SplashState; }) = _SplashState;

View file

@ -1,8 +1,16 @@
import 'package:app_flowy/user/application/sign_in_bloc.dart'; import 'package:app_flowy/user/application/sign_in_bloc.dart';
import 'package:app_flowy/user/application/sign_up_bloc.dart'; import 'package:app_flowy/user/application/sign_up_bloc.dart';
import 'package:app_flowy/user/application/splash_bloc.dart';
import 'package:app_flowy/user/domain/i_auth.dart'; import 'package:app_flowy/user/domain/i_auth.dart';
import 'package:app_flowy/user/domain/i_splash.dart';
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart'; import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
import 'package:app_flowy/user/infrastructure/i_auth_impl.dart'; import 'package:app_flowy/user/infrastructure/i_auth_impl.dart';
import 'package:app_flowy/user/infrastructure/i_splash_impl.dart';
import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart';
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
import 'package:app_flowy/workspace/application/home/home_auth_bloc.dart';
import 'package:app_flowy/workspace/domain/i_user.dart';
import 'package:app_flowy/workspace/infrastructure/i_user_impl.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
class UserDepsResolver { class UserDepsResolver {
@ -16,5 +24,17 @@ class UserDepsResolver {
//Bloc //Bloc
getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<IAuth>())); getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<IAuth>()));
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<IAuth>())); getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<IAuth>()));
getIt.registerFactory<ISplashUser>(() => SplashUserImpl());
getIt.registerFactory<ISplashRoute>(() => SplashRoute());
getIt.registerFactory<HomeBloc>(() => HomeBloc());
getIt.registerFactory<EditPannelBloc>(() => EditPannelBloc());
getIt.registerFactory<SplashBloc>(() => SplashBloc(getIt<ISplashUser>()));
getIt.registerFactoryParam<HomeAuthBloc, UserProfile, void>(
(user, _) => HomeAuthBloc(
getIt<IUserWatch>(param1: user),
),
);
} }
} }

View file

@ -1,6 +1,6 @@
import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/user/domain/i_splash.dart';
import 'package:app_flowy/user/presentation/sign_up_screen.dart'; import 'package:app_flowy/user/presentation/sign_up_screen.dart';
import 'package:app_flowy/welcome/domain/i_splash.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:flowy_infra_ui/widget/route/animation.dart'; import 'package:flowy_infra_ui/widget/route/animation.dart';
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';

View file

@ -1,11 +1,11 @@
import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/user/domain/auth_state.dart';
import 'package:app_flowy/user/domain/i_auth.dart'; import 'package:app_flowy/user/domain/i_auth.dart';
import 'package:app_flowy/user/domain/i_splash.dart';
import 'package:app_flowy/user/presentation/sign_in_screen.dart'; import 'package:app_flowy/user/presentation/sign_in_screen.dart';
import 'package:app_flowy/welcome/domain/auth_state.dart'; import 'package:app_flowy/user/presentation/welcome_screen.dart';
import 'package:app_flowy/welcome/domain/i_splash.dart';
import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; import 'package:app_flowy/workspace/presentation/home/home_screen.dart';
import 'package:app_flowy/welcome/presentation/welcome_screen.dart';
import 'package:flowy_infra/time/duration.dart'; import 'package:flowy_infra/time/duration.dart';
import 'package:flowy_infra_ui/widget/route/animation.dart'; import 'package:flowy_infra_ui/widget/route/animation.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart';
@ -13,8 +13,6 @@ import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
export 'package:app_flowy/welcome/domain/i_splash.dart';
class SplashUserImpl implements ISplashUser { class SplashUserImpl implements ISplashUser {
@override @override
Future<AuthState> currentUserProfile() { Future<AuthState> currentUserProfile() {

View file

@ -1,7 +1,7 @@
import 'package:app_flowy/welcome/domain/i_splash.dart';
import 'package:app_flowy/welcome/domain/auth_state.dart';
import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/welcome/application/splash_bloc.dart'; import 'package:app_flowy/user/application/splash_bloc.dart';
import 'package:app_flowy/user/domain/auth_state.dart';
import 'package:app_flowy/user/domain/i_splash.dart';
import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_log/flowy_log.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';

View file

@ -1,24 +0,0 @@
import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart';
import 'package:app_flowy/welcome/application/splash_bloc.dart';
import 'package:app_flowy/welcome/infrastructure/i_splash_impl.dart';
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
import 'package:app_flowy/workspace/application/home/home_auth_bloc.dart';
import 'package:app_flowy/workspace/domain/i_user.dart';
import 'package:app_flowy/workspace/infrastructure/i_user_impl.dart';
import 'package:get_it/get_it.dart';
class WelcomeDepsResolver {
static Future<void> resolve(GetIt getIt) async {
getIt.registerFactory<ISplashUser>(() => SplashUserImpl());
getIt.registerFactory<ISplashRoute>(() => SplashRoute());
getIt.registerFactory<HomeBloc>(() => HomeBloc());
getIt.registerFactory<EditPannelBloc>(() => EditPannelBloc());
getIt.registerFactory<SplashBloc>(() => SplashBloc(getIt<ISplashUser>()));
getIt.registerFactoryParam<HomeAuthBloc, UserProfile, void>(
(user, _) => HomeAuthBloc(
getIt<IUserWatch>(param1: user),
),
);
}
}

View file

@ -44,14 +44,14 @@ class AppBloc extends Bloc<AppEvent, AppState> {
} }
@freezed @freezed
abstract class AppEvent with _$AppEvent { class AppEvent with _$AppEvent {
const factory AppEvent.initial() = Initial; const factory AppEvent.initial() = Initial;
const factory AppEvent.createView( const factory AppEvent.createView(
String name, String desc, ViewType viewType) = CreateView; String name, String desc, ViewType viewType) = CreateView;
} }
@freezed @freezed
abstract class AppState implements _$AppState { class AppState with _$AppState {
const factory AppState({ const factory AppState({
required bool isLoading, required bool isLoading,
required List<View>? views, required List<View>? views,

View file

@ -36,14 +36,14 @@ class AppWatchBloc extends Bloc<AppWatchEvent, AppWatchState> {
} }
@freezed @freezed
abstract class AppWatchEvent with _$AppWatchEvent { class AppWatchEvent with _$AppWatchEvent {
const factory AppWatchEvent.started() = _Started; const factory AppWatchEvent.started() = _Started;
const factory AppWatchEvent.viewsReceived( const factory AppWatchEvent.viewsReceived(
Either<List<View>, WorkspaceError> viewsOrFail) = ViewsReceived; Either<List<View>, WorkspaceError> viewsOrFail) = ViewsReceived;
} }
@freezed @freezed
abstract class AppWatchState implements _$AppWatchState { class AppWatchState with _$AppWatchState {
const factory AppWatchState.initial() = _Initial; const factory AppWatchState.initial() = _Initial;
const factory AppWatchState.loadViews( const factory AppWatchState.loadViews(

View file

@ -21,13 +21,13 @@ class DocEditBloc extends Bloc<DocEditEvent, DocEditState> {
} }
@freezed @freezed
abstract class DocEditEvent with _$DocEditEvent { class DocEditEvent with _$DocEditEvent {
const factory DocEditEvent.initial() = Initial; const factory DocEditEvent.initial() = Initial;
const factory DocEditEvent.close() = Close; const factory DocEditEvent.close() = Close;
} }
@freezed @freezed
abstract class DocEditState implements _$DocEditState { class DocEditState with _$DocEditState {
const factory DocEditState({ const factory DocEditState({
required bool isSaving, required bool isSaving,
}) = _DocEditState; }) = _DocEditState;

View file

@ -26,7 +26,7 @@ class EditPannelBloc extends Bloc<EditPannelEvent, EditPannelState> {
} }
@freezed @freezed
abstract class EditPannelEvent with _$EditPannelEvent { class EditPannelEvent with _$EditPannelEvent {
const factory EditPannelEvent.startEdit(EditPannelContext context) = const factory EditPannelEvent.startEdit(EditPannelContext context) =
_StartEdit; _StartEdit;
@ -34,7 +34,7 @@ abstract class EditPannelEvent with _$EditPannelEvent {
} }
@freezed @freezed
abstract class EditPannelState implements _$EditPannelState { class EditPannelState with _$EditPannelState {
const factory EditPannelState({ const factory EditPannelState({
required bool isEditing, required bool isEditing,
required Option<EditPannelContext> editContext, required Option<EditPannelContext> editContext,

View file

@ -34,7 +34,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
} }
@freezed @freezed
abstract class HomeEvent with _$HomeEvent { class HomeEvent with _$HomeEvent {
const factory HomeEvent.showLoading(bool isLoading) = _ShowLoading; const factory HomeEvent.showLoading(bool isLoading) = _ShowLoading;
const factory HomeEvent.forceCollapse(bool forceCollapse) = _ForceCollapse; const factory HomeEvent.forceCollapse(bool forceCollapse) = _ForceCollapse;
const factory HomeEvent.setEditPannel(EditPannelContext editContext) = const factory HomeEvent.setEditPannel(EditPannelContext editContext) =
@ -43,7 +43,7 @@ abstract class HomeEvent with _$HomeEvent {
} }
@freezed @freezed
abstract class HomeState implements _$HomeState { class HomeState with _$HomeState {
const factory HomeState({ const factory HomeState({
required bool isLoading, required bool isLoading,
required bool forceCollapse, required bool forceCollapse,

View file

@ -48,14 +48,14 @@ class MenuWatchBloc extends Bloc<MenuWatchEvent, MenuWatchState> {
} }
@freezed @freezed
abstract class MenuWatchEvent with _$MenuWatchEvent { class MenuWatchEvent with _$MenuWatchEvent {
const factory MenuWatchEvent.started() = _Started; const factory MenuWatchEvent.started() = _Started;
const factory MenuWatchEvent.appsReceived( const factory MenuWatchEvent.appsReceived(
Either<List<App>, WorkspaceError> appsOrFail) = AppsReceived; Either<List<App>, WorkspaceError> appsOrFail) = AppsReceived;
} }
@freezed @freezed
abstract class MenuWatchState with _$MenuWatchState { class MenuWatchState with _$MenuWatchState {
const factory MenuWatchState.initial() = _Initial; const factory MenuWatchState.initial() = _Initial;
const factory MenuWatchState.loadApps( const factory MenuWatchState.loadApps(

View file

@ -23,12 +23,12 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
} }
@freezed @freezed
abstract class ViewEvent with _$ViewEvent { class ViewEvent with _$ViewEvent {
const factory ViewEvent.initial() = Initial; const factory ViewEvent.initial() = Initial;
} }
@freezed @freezed
abstract class ViewState implements _$ViewState { class ViewState with _$ViewState {
const factory ViewState({ const factory ViewState({
required bool isLoading, required bool isLoading,
required Option<View> view, required Option<View> view,

View file

@ -29,7 +29,7 @@ class ViewListEvent with _$ViewListEvent {
} }
@freezed @freezed
abstract class ViewListState implements _$ViewListState { class ViewListState with _$ViewListState {
const factory ViewListState({ const factory ViewListState({
required bool isLoading, required bool isLoading,
required Option<String> openedView, required Option<String> openedView,

View file

@ -87,7 +87,7 @@ class WelcomeBloc extends Bloc<WelcomeEvent, WelcomeState> {
} }
@freezed @freezed
abstract class WelcomeEvent with _$WelcomeEvent { class WelcomeEvent with _$WelcomeEvent {
const factory WelcomeEvent.initial() = Initial; const factory WelcomeEvent.initial() = Initial;
// const factory WelcomeEvent.fetchWorkspaces() = FetchWorkspace; // const factory WelcomeEvent.fetchWorkspaces() = FetchWorkspace;
const factory WelcomeEvent.createWorkspace(String name, String desc) = const factory WelcomeEvent.createWorkspace(String name, String desc) =
@ -100,7 +100,7 @@ abstract class WelcomeEvent with _$WelcomeEvent {
} }
@freezed @freezed
abstract class WelcomeState implements _$WelcomeState { class WelcomeState with _$WelcomeState {
const factory WelcomeState({ const factory WelcomeState({
required bool isLoading, required bool isLoading,
required List<Workspace> workspaces, required List<Workspace> workspaces,