Improve repo structure (#22)
* app updated * readme updated * rename base folder * update chatty's readme * move apps to packages dir * update repo overview Co-authored-by: diegoveloper <[email protected]>
This commit is contained in:
co-authored by
diegoveloper
parent
bd6bb66279
commit
030c3eb428
@@ -0,0 +1,32 @@
|
||||
import 'package:stream_chatter/domain/exceptions/auth_exception.dart';
|
||||
import 'package:stream_chatter/domain/usecases/login_usecase.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
enum SplashState {
|
||||
none,
|
||||
existing_user,
|
||||
new_user,
|
||||
}
|
||||
|
||||
class SplashCubit extends Cubit<SplashState> {
|
||||
SplashCubit(
|
||||
this._loginUseCase,
|
||||
) : super(SplashState.none);
|
||||
|
||||
final LoginUseCase _loginUseCase;
|
||||
|
||||
void init() async {
|
||||
try {
|
||||
final result = await _loginUseCase.validateLogin();
|
||||
if (result) {
|
||||
emit(SplashState.existing_user);
|
||||
}
|
||||
} on AuthException catch (ex) {
|
||||
if (ex.error == AuthErrorCode.not_auth) {
|
||||
emit(SplashState.none);
|
||||
} else {
|
||||
emit(SplashState.new_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'package:stream_chatter/navigator_utils.dart';
|
||||
import 'package:stream_chatter/ui/home/home_view.dart';
|
||||
import 'package:stream_chatter/ui/profile_verify/profile_verify_view.dart';
|
||||
import 'package:stream_chatter/ui/sign_in/sign_in_view.dart';
|
||||
import 'package:stream_chatter/ui/common/initial_background_view.dart';
|
||||
import 'package:stream_chatter/ui/splash/splash_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SplashView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => SplashCubit(context.read())..init(),
|
||||
child: BlocListener<SplashCubit, SplashState>(
|
||||
listener: (context, snapshot) {
|
||||
if (snapshot == SplashState.none) {
|
||||
pushAndReplaceToPage(context, SignInView());
|
||||
} else if (snapshot == SplashState.existing_user) {
|
||||
pushAndReplaceToPage(context, HomeView());
|
||||
} else {
|
||||
pushAndReplaceToPage(context, ProfileVerifyView());
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
InitialBackgroundView(),
|
||||
Center(
|
||||
child: Hero(
|
||||
tag: 'logo_hero',
|
||||
child: Image.asset(
|
||||
'assets/logo.png',
|
||||
height: 100,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user