2021-07-25 18:04:16 +08:00
|
|
|
import 'package:app_flowy/startup/startup.dart';
|
|
|
|
import 'package:app_flowy/user/domain/i_auth.dart';
|
2021-09-06 16:18:34 +08:00
|
|
|
import 'package:app_flowy/user/presentation/sign_in_screen.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
import 'package:app_flowy/welcome/domain/auth_state.dart';
|
2021-09-08 13:50:20 +08:00
|
|
|
import 'package:app_flowy/welcome/domain/i_splash.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-09-06 16:18:34 +08:00
|
|
|
import 'package:app_flowy/welcome/presentation/welcome_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-07-13 14:28:01 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-user/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
|
|
|
export 'package:app_flowy/welcome/domain/i_splash.dart';
|
2021-07-12 23:27:58 +08:00
|
|
|
|
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-17 19:03:46 +08:00
|
|
|
final result = UserEventInitUser().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
|
|
|
},
|
|
|
|
(userError) {
|
|
|
|
return AuthState.unauthenticated(userError);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-06 16:18:34 +08:00
|
|
|
void pushHomeScreen(
|
|
|
|
BuildContext context, UserProfile userProfile, String workspaceId) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
PageRoutes.fade(() => HomeScreen(userProfile, workspaceId),
|
|
|
|
RouteDurations.slow.inMilliseconds * .001),
|
|
|
|
);
|
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,
|
|
|
|
PageRoutes.fade(() => SignInScreen(router: getIt<IAuthRouter>()),
|
|
|
|
RouteDurations.slow.inMilliseconds * .001),
|
|
|
|
);
|
2021-08-30 16:18:58 +08:00
|
|
|
}
|
2021-07-12 23:27:58 +08:00
|
|
|
}
|