2021-07-25 18:04:16 +08:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
2021-10-09 10:09:31 +08:00
|
|
|
import 'package:app_flowy/user/domain/auth_state.dart';
|
2021-07-25 18:04:16 +08:00
|
|
|
import 'package:app_flowy/user/domain/i_auth.dart';
|
2021-10-09 10:09:31 +08:00
|
|
|
import 'package:app_flowy/user/domain/i_splash.dart';
|
2021-09-06 16:18:34 +08:00
|
|
|
import 'package:app_flowy/user/presentation/sign_in_screen.dart';
|
2021-11-07 18:19:58 +08:00
|
|
|
import 'package:app_flowy/user/presentation/skip_log_in_screen.dart';
|
2021-10-09 10:09:31 +08:00
|
|
|
import 'package:app_flowy/user/presentation/welcome_screen.dart';
|
2021-08-30 16:18:58 +08:00
|
|
|
import 'package:app_flowy/workspace/infrastructure/repos/user_repo.dart';
|
2021-07-22 17:06:53 +08:00
|
|
|
import 'package:app_flowy/workspace/presentation/home/home_screen.dart';
|
2021-08-30 16:18:58 +08:00
|
|
|
import 'package:flowy_infra/time/duration.dart';
|
|
|
|
import 'package:flowy_infra_ui/widget/route/animation.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
2021-12-19 21:29:33 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile;
|
|
|
|
import 'package:flowy_sdk/protobuf/flowy-core-data-model/protobuf.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
2021-09-08 13:50:20 +08:00
|
|
|
class SplashUserImpl implements ISplashUser {
|
2021-07-12 23:27:58 +08:00
|
|
|
@override
|
2021-09-04 16:53:58 +08:00
|
|
|
Future<AuthState> currentUserProfile() {
|
2021-09-25 21:47:02 +08:00
|
|
|
final result = UserEventCheckUser().send();
|
2021-07-12 23:27:58 +08:00
|
|
|
return result.then((result) {
|
|
|
|
return result.fold(
|
2021-09-06 16:18:34 +08:00
|
|
|
(userProfile) {
|
|
|
|
return AuthState.authenticated(userProfile);
|
2021-07-12 23:27:58 +08:00
|
|
|
},
|
2022-01-04 22:44:03 +08:00
|
|
|
(error) {
|
|
|
|
return AuthState.unauthenticated(error);
|
2021-07-12 23:27:58 +08:00
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:50:20 +08:00
|
|
|
class SplashRoute implements ISplashRoute {
|
2021-07-12 23:27:58 +08:00
|
|
|
@override
|
2021-09-06 16:18:34 +08:00
|
|
|
Future<void> pushWelcomeScreen(BuildContext context, UserProfile user) async {
|
2021-08-30 16:18:58 +08:00
|
|
|
final repo = UserRepo(user: user);
|
2021-09-06 16:18:34 +08:00
|
|
|
final screen = WelcomeScreen(repo: repo);
|
|
|
|
final workspaceId = await Navigator.of(context).push(
|
|
|
|
PageRoutes.fade(
|
|
|
|
() => screen,
|
|
|
|
RouteDurations.slow.inMilliseconds * .001,
|
|
|
|
),
|
2021-08-30 16:18:58 +08:00
|
|
|
);
|
2021-09-06 16:18:34 +08:00
|
|
|
|
|
|
|
pushHomeScreen(context, repo.user, workspaceId);
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-11-10 23:39:51 +08:00
|
|
|
void pushHomeScreen(BuildContext context, UserProfile userProfile, CurrentWorkspaceSetting workspaceSetting) {
|
2021-09-06 16:18:34 +08:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
2021-11-10 23:39:51 +08:00
|
|
|
PageRoutes.fade(() => HomeScreen(userProfile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001),
|
2021-09-06 16:18:34 +08:00
|
|
|
);
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|
2021-08-30 16:18:58 +08:00
|
|
|
|
2021-09-06 16:18:34 +08:00
|
|
|
@override
|
|
|
|
void pushSignInScreen(BuildContext context) {
|
2021-08-30 16:18:58 +08:00
|
|
|
Navigator.push(
|
2021-09-06 16:18:34 +08:00
|
|
|
context,
|
2021-11-08 14:11:10 +08:00
|
|
|
PageRoutes.fade(() => SignInScreen(router: getIt<IAuthRouter>()), RouteDurations.slow.inMilliseconds * .001),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void pushSkipLoginScreen(BuildContext context) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
PageRoutes.fade(
|
|
|
|
() => SkipLogInScreen(
|
|
|
|
router: getIt<IAuthRouter>(),
|
|
|
|
authManager: getIt<IAuth>(),
|
|
|
|
),
|
|
|
|
RouteDurations.slow.inMilliseconds * .001),
|
2021-09-06 16:18:34 +08:00
|
|
|
);
|
2021-08-30 16:18:58 +08:00
|
|
|
}
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|