2023-05-21 18:53:59 +08:00
|
|
|
import 'package:appflowy/core/config/kv.dart';
|
|
|
|
import 'package:appflowy/core/config/kv_keys.dart';
|
|
|
|
import 'package:appflowy/core/frameless_window.dart';
|
2023-08-14 13:34:01 -07:00
|
|
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-08-09 10:13:49 +08:00
|
|
|
import 'package:appflowy/user/application/historical_user_bloc.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/user/application/sign_in_bloc.dart';
|
|
|
|
import 'package:appflowy/user/presentation/router.dart';
|
|
|
|
import 'package:appflowy/user/presentation/widgets/background.dart';
|
2023-08-17 23:46:39 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
|
2021-12-07 23:01:23 +05:30
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-10-20 14:56:25 +08:00
|
|
|
import 'package:flowy_infra/size.dart';
|
2023-05-21 18:53:59 +08:00
|
|
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
2021-07-25 16:07:53 +08:00
|
|
|
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
|
|
|
import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
|
2021-10-09 16:43:56 +08:00
|
|
|
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
|
2023-01-08 12:10:53 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
2021-07-13 13:14:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2021-07-25 16:07:53 +08:00
|
|
|
import 'package:dartz/dartz.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
2021-07-13 13:14:49 +08:00
|
|
|
|
|
|
|
class SignInScreen extends StatelessWidget {
|
2023-05-21 18:53:59 +08:00
|
|
|
const SignInScreen({
|
|
|
|
super.key,
|
|
|
|
required this.router,
|
|
|
|
});
|
|
|
|
|
2022-01-31 08:15:49 +08:00
|
|
|
final AuthRouter router;
|
2021-07-13 13:14:49 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocProvider(
|
|
|
|
create: (context) => getIt<SignInBloc>(),
|
2023-05-21 18:53:59 +08:00
|
|
|
child: BlocConsumer<SignInBloc, SignInState>(
|
2021-07-25 18:04:16 +08:00
|
|
|
listener: (context, state) {
|
|
|
|
state.successOrFail.fold(
|
|
|
|
() => null,
|
|
|
|
(result) => _handleSuccessOrFail(result, context),
|
|
|
|
);
|
|
|
|
},
|
2023-05-21 18:53:59 +08:00
|
|
|
builder: (_, __) => Scaffold(
|
|
|
|
appBar: const PreferredSize(
|
|
|
|
preferredSize: Size(double.infinity, 60),
|
|
|
|
child: MoveWindowDetector(),
|
|
|
|
),
|
2021-07-25 18:04:16 +08:00
|
|
|
body: SignInForm(router: router),
|
2021-07-25 16:07:53 +08:00
|
|
|
),
|
2021-07-13 13:14:49 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-07-25 16:07:53 +08:00
|
|
|
|
2022-10-25 19:49:58 +08:00
|
|
|
void _handleSuccessOrFail(
|
2023-04-10 15:10:42 +08:00
|
|
|
Either<UserProfilePB, FlowyError> result,
|
|
|
|
BuildContext context,
|
|
|
|
) {
|
2021-07-25 18:04:16 +08:00
|
|
|
result.fold(
|
2023-08-17 23:46:39 +08:00
|
|
|
(user) {
|
|
|
|
if (user.encryptionType == EncryptionTypePB.Symmetric) {
|
|
|
|
router.pushEncryptionScreen(context, user);
|
|
|
|
} else {
|
|
|
|
router.pushHomeScreen(context, user);
|
|
|
|
}
|
|
|
|
},
|
2021-10-09 16:43:56 +08:00
|
|
|
(error) => showSnapBar(context, error.msg),
|
2021-07-25 16:07:53 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SignInForm extends StatelessWidget {
|
|
|
|
const SignInForm({
|
2023-05-21 18:53:59 +08:00
|
|
|
super.key,
|
2021-07-25 18:04:16 +08:00
|
|
|
required this.router,
|
2023-05-21 18:53:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
final AuthRouter router;
|
2021-07-25 16:07:53 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-08-08 11:24:06 +08:00
|
|
|
final isSubmitting = context.read<SignInBloc>().state.isSubmitting;
|
|
|
|
const indicatorMinHeight = 4.0;
|
2021-07-25 16:07:53 +08:00
|
|
|
return Align(
|
|
|
|
alignment: Alignment.center,
|
2021-09-05 22:52:20 +08:00
|
|
|
child: AuthFormContainer(
|
2021-07-25 16:07:53 +08:00
|
|
|
children: [
|
2023-05-21 18:53:59 +08:00
|
|
|
// Email.
|
2021-12-07 23:01:23 +05:30
|
|
|
FlowyLogoTitle(
|
|
|
|
title: LocaleKeys.signIn_loginTitle.tr(),
|
|
|
|
logoSize: const Size(60, 60),
|
2021-07-25 16:07:53 +08:00
|
|
|
),
|
|
|
|
const VSpace(30),
|
2023-05-21 18:53:59 +08:00
|
|
|
// Email and password. don't support yet.
|
|
|
|
/*
|
|
|
|
...[
|
|
|
|
const EmailTextField(),
|
|
|
|
const VSpace(5),
|
|
|
|
const PasswordTextField(),
|
|
|
|
const VSpace(20),
|
|
|
|
const LoginButton(),
|
|
|
|
const VSpace(10),
|
|
|
|
|
|
|
|
const VSpace(10),
|
|
|
|
SignUpPrompt(router: router),
|
|
|
|
],
|
|
|
|
*/
|
|
|
|
|
|
|
|
const SignInAsGuestButton(),
|
|
|
|
|
|
|
|
// third-party sign in.
|
|
|
|
const VSpace(20),
|
|
|
|
const OrContinueWith(),
|
2021-07-25 16:07:53 +08:00
|
|
|
const VSpace(10),
|
2023-05-21 18:53:59 +08:00
|
|
|
const ThirdPartySignInButtons(),
|
|
|
|
const VSpace(20),
|
|
|
|
// loading status
|
2023-08-08 11:24:06 +08:00
|
|
|
...isSubmitting
|
|
|
|
? [
|
|
|
|
const VSpace(indicatorMinHeight),
|
|
|
|
const LinearProgressIndicator(
|
|
|
|
value: null,
|
|
|
|
minHeight: indicatorMinHeight,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
const VSpace(indicatorMinHeight * 2.0)
|
|
|
|
], // add the same space when there's no loading status.
|
2023-08-09 10:13:49 +08:00
|
|
|
// ConstrainedBox(
|
|
|
|
// constraints: const BoxConstraints(maxHeight: 140),
|
|
|
|
// child: HistoricalUserList(
|
|
|
|
// didOpenUser: () async {
|
|
|
|
// await FlowyRunner.run(
|
|
|
|
// FlowyApp(),
|
|
|
|
// integrationEnv(),
|
|
|
|
// );
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
const VSpace(20),
|
2021-07-25 16:07:53 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-07-25 18:04:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class SignUpPrompt extends StatelessWidget {
|
|
|
|
const SignUpPrompt({
|
|
|
|
Key? key,
|
|
|
|
required this.router,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-01-31 08:15:49 +08:00
|
|
|
final AuthRouter router;
|
2021-07-25 18:04:16 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
2022-08-31 09:19:31 +08:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2021-07-25 18:04:16 +08:00
|
|
|
children: [
|
2022-10-25 19:49:58 +08:00
|
|
|
FlowyText.medium(
|
|
|
|
LocaleKeys.signIn_dontHaveAnAccount.tr(),
|
2022-11-10 14:22:18 +08:00
|
|
|
color: Theme.of(context).hintColor,
|
2022-10-25 19:49:58 +08:00
|
|
|
),
|
2021-07-25 18:04:16 +08:00
|
|
|
TextButton(
|
2022-11-22 20:00:21 +08:00
|
|
|
style: TextButton.styleFrom(
|
2023-04-10 15:10:42 +08:00
|
|
|
textStyle: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
2021-09-06 16:18:34 +08:00
|
|
|
onPressed: () => router.pushSignUpScreen(context),
|
2021-09-05 18:02:49 +08:00
|
|
|
child: Text(
|
2021-12-07 23:01:23 +05:30
|
|
|
LocaleKeys.signUp_buttonText.tr(),
|
2022-11-10 14:22:18 +08:00
|
|
|
style: TextStyle(color: Theme.of(context).colorScheme.primary),
|
2021-07-25 18:04:16 +08:00
|
|
|
),
|
|
|
|
),
|
2023-05-21 18:53:59 +08:00
|
|
|
ForgetPasswordButton(router: router),
|
2021-07-25 18:04:16 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LoginButton extends StatelessWidget {
|
|
|
|
const LoginButton({
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-25 22:09:52 +08:00
|
|
|
return RoundedTextButton(
|
2021-12-07 23:01:23 +05:30
|
|
|
title: LocaleKeys.signIn_loginButtonText.tr(),
|
2021-09-05 22:52:20 +08:00
|
|
|
height: 48,
|
2021-10-20 14:56:25 +08:00
|
|
|
borderRadius: Corners.s10Border,
|
2022-11-10 14:22:18 +08:00
|
|
|
onPressed: () => context
|
|
|
|
.read<SignInBloc>()
|
|
|
|
.add(const SignInEvent.signedInWithUserEmailAndPassword()),
|
2021-07-25 18:04:16 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-21 18:53:59 +08:00
|
|
|
class SignInAsGuestButton extends StatelessWidget {
|
|
|
|
const SignInAsGuestButton({
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-08-09 10:13:49 +08:00
|
|
|
return BlocProvider(
|
|
|
|
create: (context) => HistoricalUserBloc()
|
|
|
|
..add(
|
|
|
|
const HistoricalUserEvent.initial(),
|
|
|
|
),
|
|
|
|
child: BlocListener<HistoricalUserBloc, HistoricalUserState>(
|
|
|
|
listenWhen: (previous, current) =>
|
|
|
|
previous.openedHistoricalUser != current.openedHistoricalUser,
|
|
|
|
listener: (context, state) async {
|
2023-08-17 23:46:39 +08:00
|
|
|
await runAppFlowy();
|
2023-08-09 10:13:49 +08:00
|
|
|
},
|
|
|
|
child: BlocBuilder<HistoricalUserBloc, HistoricalUserState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state.historicalUsers.isEmpty) {
|
|
|
|
return RoundedTextButton(
|
|
|
|
title: LocaleKeys.signIn_loginAsGuestButtonText.tr(),
|
|
|
|
height: 48,
|
|
|
|
borderRadius: Corners.s6Border,
|
|
|
|
onPressed: () {
|
|
|
|
getIt<KeyValueStorage>().set(KVKeys.loginType, 'local');
|
|
|
|
context
|
|
|
|
.read<SignInBloc>()
|
|
|
|
.add(const SignInEvent.signedInAsGuest());
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return RoundedTextButton(
|
|
|
|
title: LocaleKeys.signIn_continueAnonymousUser.tr(),
|
|
|
|
height: 48,
|
|
|
|
borderRadius: Corners.s6Border,
|
|
|
|
onPressed: () {
|
|
|
|
final bloc = context.read<HistoricalUserBloc>();
|
|
|
|
final user = bloc.state.historicalUsers.first;
|
|
|
|
bloc.add(HistoricalUserEvent.openHistoricalUser(user));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2023-05-21 18:53:59 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-25 18:04:16 +08:00
|
|
|
class ForgetPasswordButton extends StatelessWidget {
|
|
|
|
const ForgetPasswordButton({
|
|
|
|
Key? key,
|
|
|
|
required this.router,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-01-31 08:15:49 +08:00
|
|
|
final AuthRouter router;
|
2021-07-25 18:04:16 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return TextButton(
|
|
|
|
style: TextButton.styleFrom(
|
2023-04-10 15:10:42 +08:00
|
|
|
textStyle: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
),
|
2023-05-21 18:53:59 +08:00
|
|
|
onPressed: () {
|
|
|
|
throw UnimplementedError();
|
|
|
|
},
|
2021-09-05 18:02:49 +08:00
|
|
|
child: Text(
|
2021-12-07 23:01:23 +05:30
|
|
|
LocaleKeys.signIn_forgotPassword.tr(),
|
2022-11-10 14:22:18 +08:00
|
|
|
style: TextStyle(color: Theme.of(context).colorScheme.primary),
|
2021-07-25 18:04:16 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-07-25 16:07:53 +08:00
|
|
|
|
2021-07-25 18:04:16 +08:00
|
|
|
class PasswordTextField extends StatelessWidget {
|
|
|
|
const PasswordTextField({
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocBuilder<SignInBloc, SignInState>(
|
2022-10-25 19:49:58 +08:00
|
|
|
buildWhen: (previous, current) =>
|
|
|
|
previous.passwordError != current.passwordError,
|
2021-07-25 18:04:16 +08:00
|
|
|
builder: (context, state) {
|
|
|
|
return RoundedInputField(
|
|
|
|
obscureText: true,
|
2023-08-14 13:34:01 -07:00
|
|
|
obscureIcon: const FlowySvg(FlowySvgs.hide_m),
|
|
|
|
obscureHideIcon: const FlowySvg(FlowySvgs.show_m),
|
2021-12-07 23:01:23 +05:30
|
|
|
hintText: LocaleKeys.signIn_passwordHint.tr(),
|
2022-10-25 19:49:58 +08:00
|
|
|
errorText: context
|
|
|
|
.read<SignInBloc>()
|
|
|
|
.state
|
|
|
|
.passwordError
|
|
|
|
.fold(() => "", (error) => error),
|
|
|
|
onChanged: (value) => context
|
|
|
|
.read<SignInBloc>()
|
|
|
|
.add(SignInEvent.passwordChanged(value)),
|
2021-07-25 18:04:16 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class EmailTextField extends StatelessWidget {
|
|
|
|
const EmailTextField({
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocBuilder<SignInBloc, SignInState>(
|
2022-10-25 19:49:58 +08:00
|
|
|
buildWhen: (previous, current) =>
|
|
|
|
previous.emailError != current.emailError,
|
2021-07-25 18:04:16 +08:00
|
|
|
builder: (context, state) {
|
|
|
|
return RoundedInputField(
|
2021-12-07 23:01:23 +05:30
|
|
|
hintText: LocaleKeys.signIn_emailHint.tr(),
|
2022-10-25 19:49:58 +08:00
|
|
|
errorText: context
|
|
|
|
.read<SignInBloc>()
|
|
|
|
.state
|
|
|
|
.emailError
|
|
|
|
.fold(() => "", (error) => error),
|
|
|
|
onChanged: (value) =>
|
|
|
|
context.read<SignInBloc>().add(SignInEvent.emailChanged(value)),
|
2021-07-25 18:04:16 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2021-07-25 16:07:53 +08:00
|
|
|
}
|
2021-07-13 13:14:49 +08:00
|
|
|
}
|
2023-05-21 18:53:59 +08:00
|
|
|
|
|
|
|
class OrContinueWith extends StatelessWidget {
|
|
|
|
const OrContinueWith({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-28 05:09:39 +01:00
|
|
|
return const Row(
|
2023-05-21 18:53:59 +08:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
2023-05-28 05:09:39 +01:00
|
|
|
children: [
|
2023-05-21 18:53:59 +08:00
|
|
|
Flexible(
|
|
|
|
child: Divider(
|
|
|
|
color: Colors.white,
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
FlowyText.regular(' Or continue with '),
|
|
|
|
Flexible(
|
|
|
|
child: Divider(
|
|
|
|
color: Colors.white,
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ThirdPartySignInButton extends StatelessWidget {
|
|
|
|
const ThirdPartySignInButton({
|
|
|
|
Key? key,
|
|
|
|
required this.icon,
|
|
|
|
required this.onPressed,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2023-08-14 13:34:01 -07:00
|
|
|
final FlowySvgData icon;
|
2023-05-21 18:53:59 +08:00
|
|
|
final VoidCallback onPressed;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FlowyIconButton(
|
|
|
|
height: 48,
|
|
|
|
width: 48,
|
|
|
|
iconPadding: const EdgeInsets.all(8.0),
|
|
|
|
radius: Corners.s10Border,
|
|
|
|
onPressed: onPressed,
|
2023-08-14 13:34:01 -07:00
|
|
|
icon: FlowySvg(
|
2023-05-21 18:53:59 +08:00
|
|
|
icon,
|
2023-08-18 00:39:02 -07:00
|
|
|
blendMode: null,
|
2023-05-21 18:53:59 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ThirdPartySignInButtons extends StatelessWidget {
|
2023-08-07 22:24:04 +08:00
|
|
|
final MainAxisAlignment mainAxisAlignment;
|
2023-05-21 18:53:59 +08:00
|
|
|
const ThirdPartySignInButtons({
|
2023-08-07 22:24:04 +08:00
|
|
|
this.mainAxisAlignment = MainAxisAlignment.center,
|
2023-05-21 18:53:59 +08:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
2023-08-07 22:24:04 +08:00
|
|
|
mainAxisAlignment: mainAxisAlignment,
|
2023-05-21 18:53:59 +08:00
|
|
|
children: [
|
|
|
|
ThirdPartySignInButton(
|
2023-08-14 13:34:01 -07:00
|
|
|
icon: FlowySvgs.google_mark_xl,
|
2023-05-21 18:53:59 +08:00
|
|
|
onPressed: () {
|
|
|
|
getIt<KeyValueStorage>().set(KVKeys.loginType, 'supabase');
|
2023-08-03 08:48:04 +08:00
|
|
|
context.read<SignInBloc>().add(
|
|
|
|
const SignInEvent.signedInWithOAuth('google'),
|
|
|
|
);
|
2023-05-21 18:53:59 +08:00
|
|
|
},
|
|
|
|
),
|
2023-08-03 08:48:04 +08:00
|
|
|
// const SizedBox(width: 20),
|
|
|
|
// ThirdPartySignInButton(
|
|
|
|
// icon: 'login/github-mark',
|
|
|
|
// onPressed: () {
|
|
|
|
// getIt<KeyValueStorage>().set(KVKeys.loginType, 'supabase');
|
|
|
|
// context
|
|
|
|
// .read<SignInBloc>()
|
|
|
|
// .add(const SignInEvent.signedInWithOAuth('github'));
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// const SizedBox(width: 20),
|
|
|
|
// ThirdPartySignInButton(
|
|
|
|
// icon: 'login/discord-mark',
|
|
|
|
// onPressed: () {
|
|
|
|
// getIt<KeyValueStorage>().set(KVKeys.loginType, 'supabase');
|
|
|
|
// context
|
|
|
|
// .read<SignInBloc>()
|
|
|
|
// .add(const SignInEvent.signedInWithOAuth('discord'));
|
|
|
|
// },
|
|
|
|
// ),
|
2023-05-21 18:53:59 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|