[flutter]: config skip screen ui

This commit is contained in:
appflowy 2021-11-08 14:11:10 +08:00
parent 55ea9e6cae
commit b8dcc9414d
10 changed files with 78 additions and 91 deletions

View File

@ -8,8 +8,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
part 'sign_in_bloc.freezed.dart';
class SignInBloc extends Bloc<SignInEvent, SignInState> {
final IAuth authImpl;
SignInBloc(this.authImpl) : super(SignInState.initial());
final IAuth authManager;
SignInBloc(this.authManager) : super(SignInState.initial());
@override
Stream<SignInState> mapEventToState(
@ -33,7 +33,7 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
Stream<SignInState> _performActionOnSignIn(SignInState state) async* {
yield state.copyWith(isSubmitting: true, emailError: none(), passwordError: none(), successOrFail: none());
final result = await authImpl.signIn(state.email, state.password);
final result = await authManager.signIn(state.email, state.password);
yield result.fold(
(userProfile) => state.copyWith(isSubmitting: false, successOrFail: some(left(userProfile))),
(error) => stateFromCode(error),

View File

@ -3,10 +3,8 @@ import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart';
abstract class IAuth {
Future<Either<UserProfile, UserError>> signIn(
String? email, String? password);
Future<Either<UserProfile, UserError>> signUp(
String? name, String? password, String? email);
Future<Either<UserProfile, UserError>> signIn(String? email, String? password);
Future<Either<UserProfile, UserError>> signUp(String? name, String? password, String? email);
Future<Either<Unit, UserError>> signOut();
}

View File

@ -17,7 +17,8 @@ abstract class ISplashUserWatch {
abstract class ISplashRoute {
void pushSignInScreen(BuildContext context);
void pushSkipLoginScreen(BuildContext context);
Future<void> pushWelcomeScreen(BuildContext context, UserProfile profile);
void pushHomeScreen(
BuildContext context, UserProfile profile, String workspaceId);
void pushHomeScreen(BuildContext context, UserProfile profile, String workspaceId);
}

View File

@ -15,14 +15,12 @@ class AuthImpl extends IAuth {
});
@override
Future<Either<UserProfile, UserError>> signIn(
String? email, String? password) {
Future<Either<UserProfile, UserError>> signIn(String? email, String? password) {
return repo.signIn(email: email, password: password);
}
@override
Future<Either<UserProfile, UserError>> signUp(
String? name, String? password, String? email) {
Future<Either<UserProfile, UserError>> signUp(String? name, String? password, String? email) {
return repo.signUp(name: name, password: password, email: email);
}

View File

@ -58,7 +58,20 @@ class SplashRoute implements ISplashRoute {
void pushSignInScreen(BuildContext context) {
Navigator.push(
context,
PageRoutes.fade(() => SkipLogInScreen(router: getIt<IAuthRouter>()), RouteDurations.slow.inMilliseconds * .001),
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),
);
}
}

View File

@ -58,7 +58,7 @@ class SignInForm extends StatelessWidget {
alignment: Alignment.center,
child: AuthFormContainer(
children: [
const AuthFormTitle(
const FlowyLogoTitle(
title: 'Login to Appflowy',
logoSize: Size(60, 60),
),

View File

@ -53,7 +53,7 @@ class SignUpForm extends StatelessWidget {
alignment: Alignment.center,
child: AuthFormContainer(
children: [
const AuthFormTitle(
const FlowyLogoTitle(
title: 'Sign Up to Appflowy',
logoSize: Size(60, 60),
),

View File

@ -1,47 +1,22 @@
// ignore_for_file: prefer_const_constructors
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/user/application/sign_in_bloc.dart';
import 'package:app_flowy/user/domain/i_auth.dart';
import 'package:app_flowy/user/presentation/widgets/background.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra_ui/widget/rounded_button.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
import 'package:flowy_sdk/protobuf/flowy-user/errors.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:url_launcher/url_launcher.dart';
class SkipLogInScreen extends StatelessWidget {
final IAuthRouter router;
const SkipLogInScreen({Key? key, required this.router}) : super(key: key);
final IAuth authManager;
const SkipLogInScreen({Key? key, required this.router, required this.authManager}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => getIt<SignInBloc>(),
child: BlocListener<SignInBloc, SignInState>(
listener: (context, state) {
state.successOrFail.fold(
() => null,
(result) => _handleSuccessOrFail(result, context),
);
},
child: Scaffold(
body: SignInForm(router: router),
),
),
);
}
void _handleSuccessOrFail(Either<UserProfile, UserError> result, BuildContext context) {
result.fold(
(user) => router.pushWelcomeScreen(context, user),
(error) => showSnapBar(context, error.msg),
return Scaffold(
body: SignInForm(router: router),
);
}
}
@ -57,45 +32,43 @@ class SignInForm extends StatelessWidget {
Widget build(BuildContext context) {
return Center(
child: SizedBox(
width: 600,
width: 400,
height: 600,
child: Expanded(
child: Column(
// ignore: prefer_const_literals_to_create_immutables
children: [
const AuthFormTitle(
title: 'Welcome to AppFlowy',
logoSize: Size(60, 60),
),
const VSpace(80),
const GoButton(),
const VSpace(30),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// ignore: prefer_const_constructors
InkWell(
child: Text(
'Star on Github',
style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
),
onTap: () {
_launchURL('https://github.com/AppFlowy-IO/appflowy');
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const FlowyLogoTitle(
title: 'Welcome to AppFlowy',
logoSize: Size.square(60),
),
const VSpace(80),
GoButton(onPressed: _autoRegister),
const VSpace(30),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
child: const Text(
'Star on Github',
style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
),
HSpace(60),
InkWell(
child: Text(
'Subscribe to Newsletter',
style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
),
onTap: () {
_launchURL('https://www.appflowy.io/blog');
}),
],
)
],
),
onTap: () {
_launchURL('https://github.com/AppFlowy-IO/appflowy');
},
),
const Spacer(),
InkWell(
child: const Text(
'Subscribe to Newsletter',
style: TextStyle(decoration: TextDecoration.underline, color: Colors.blue),
),
onTap: () {
_launchURL('https://www.appflowy.io/blog');
},
),
],
)
],
),
),
);
@ -108,11 +81,15 @@ class SignInForm extends StatelessWidget {
throw 'Could not launch $url';
}
}
void _autoRegister() {}
}
class GoButton extends StatelessWidget {
final VoidCallback onPressed;
const GoButton({
Key? key,
required this.onPressed,
}) : super(key: key);
@override
@ -120,12 +97,10 @@ class GoButton extends StatelessWidget {
final theme = context.watch<AppTheme>();
return RoundedTextButton(
title: 'Let\'s Go',
height: 60,
height: 50,
borderRadius: Corners.s10Border,
color: theme.main1,
onPressed: () {
//to do: direct to the workspace
},
onPressed: onPressed,
);
}
}

View File

@ -59,7 +59,9 @@ class SplashScreen extends StatelessWidget {
void _handleUnauthenticated(BuildContext context, Unauthenticated result) {
Log.error(result.error);
getIt<ISplashRoute>().pushSignInScreen(context);
// getIt<ISplashRoute>().pushSignInScreen(context);
getIt<ISplashRoute>().pushSkipLoginScreen(context);
}
}

View File

@ -26,13 +26,13 @@ class AuthFormContainer extends StatelessWidget {
}
}
class AuthFormTitle extends StatelessWidget {
class FlowyLogoTitle extends StatelessWidget {
final String title;
final Size logoSize;
const AuthFormTitle({
const FlowyLogoTitle({
Key? key,
required this.title,
required this.logoSize,
this.logoSize = const Size.square(40),
}) : super(key: key);
@override
@ -43,7 +43,7 @@ class AuthFormTitle extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox.fromSize(
size: const Size.square(40),
size: logoSize,
child: svg("flowy_logo"),
),
const VSpace(30),