Skip to content

Commit

Permalink
fix home screen not displaying users 🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
olawills committed Oct 4, 2023
1 parent 2810839 commit c6fc591
Show file tree
Hide file tree
Showing 42 changed files with 447 additions and 301 deletions.
4 changes: 2 additions & 2 deletions lib/app/common/extensions/app_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ extension OnTextExtension on Widget {
}

extension OnWidthSpacer on num {
Widget get sbW => SizedBox(width: w);
Widget get sbw => SizedBox(width: w);
}

extension OnHeightSpacer on num {
Widget get sbH => SizedBox(height: h);
Widget get sbh => SizedBox(height: h);
}

extension OnCenter on Widget {
Expand Down
5 changes: 5 additions & 0 deletions lib/app/common/utils/enums.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum RequestStte {
loading,
success,
error,
}
6 changes: 3 additions & 3 deletions lib/app/common/widgets/no_internet_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class NoInternetConnectionWidget extends StatelessWidget {
Assets.noInternetImage,
height: 200.h,
),
10.sbH,
10.sbh,
ReusableText(
text: AppString.connectionMessage,
style: appMStyle(24, kDarkWithOp, FontWeight.bold),
),
15.sbH,
15.sbh,
ReusableText(
text: AppString.socketException,
style: appMStyle(16, kDarkWithOp, FontWeight.w400),
),
20.sbH,
20.sbh,
CustomElevatedButton(
onPressed: onPressed,
text: 'Refresh',
Expand Down
6 changes: 3 additions & 3 deletions lib/app/common/widgets/onscreen_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _AppKeyBoardState extends State<AppKeyBoard> {
children: [
Row(
children: [
_buildKeypadButton('1', child: 15.sbH),
_buildKeypadButton('1', child: 15.sbh),
_buildKeypadButton('2', alphabets: 'ABC'),
_buildKeypadButton('3', alphabets: 'DEF'),
],
Expand All @@ -56,9 +56,9 @@ class _AppKeyBoardState extends State<AppKeyBoard> {
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(child: Container()),
_buildKeypadButton('0', child: 15.sbH),
_buildKeypadButton('0', child: 15.sbh),
_buildKeypadButton('⌫',
child: 15.sbH,
child: 15.sbh,
color: Color(kDarkGrey.value).withOpacity(0.1),
onPressed: _backspace),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import 'package:dating_app/src/startup/presentation/bloc/onboarding_bloc.dart';
import 'package:dio/dio.dart';
import 'package:get_it/get_it.dart';

import 'app/core/network/dio_client.dart';
import 'src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import 'src/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import 'src/features/cubit/bottom_navbar/bottom_navigation_cubit.dart';
import 'src/features/cubit/internet_connection/internet_connection_cubit.dart';
import 'src/features/home/data/datasources/user_remote_data_source.dart';
import 'src/features/home/data/repository/user_repository.dart';
import 'src/features/home/presentation/bloc/users_bloc.dart';
import '../network/dio_client.dart';
import '../../../src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import '../../../src/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import '../../../src/features/cubit/bottom_navbar/bottom_navigation_cubit.dart';
import '../../../src/features/cubit/internet_connection/internet_connection_cubit.dart';
import '../../../src/features/home/data/datasources/user_remote_data_source.dart';
import '../../../src/features/home/data/repository/user_repository.dart';
import '../../../src/features/home/presentation/bloc/users_bloc.dart';

GetIt serviceLocator = GetIt.instance;

Expand All @@ -35,10 +35,10 @@ class ServiceLocator {
() => InternetConnectionCubit(connectivity: serviceLocator()));

// Data Source
serviceLocator.registerFactory<AuthRemoteDataSource>(
() => AuthRemoteDataSourceImpl());
serviceLocator.registerFactory<UserRemoteDataSource>(
() => UserRemoteDataSourceImpl());
serviceLocator
.registerFactory<AuthRemoteDataSource>(() => AuthRemoteDataSource());
serviceLocator
.registerFactory<UserRemoteDataSource>(() => UserRemoteDataSource());
serviceLocator.registerFactory<AuthInfoRemoteDataSource>(
() => AuthInfoRemoteDataSourceImpl());

Expand Down
2 changes: 1 addition & 1 deletion lib/app/core/domain/all_blocs.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/injection_container.dart';
import 'package:dating_app/app/core/config/injection_container.dart';
import 'package:dating_app/src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';

import '../../../src/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
Expand Down
3 changes: 1 addition & 2 deletions lib/app/core/network/dio_interceptors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class DioInterceptor extends Interceptor {
Log.info('==================START====================');
Log.info(
'Request => ${options.baseUrl} ${options.path}${options.queryParameters}');
Log.info('Headers => ${options.headers}');
Log.info('Request: ${options.method} ${options.uri}');
Log.info('Data: ${options.data}');
return super.onRequest(options, handler);
Expand All @@ -16,7 +15,7 @@ class DioInterceptor extends Interceptor {
@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
Log.debug(
'Response => StatusCode: ${response.statusCode}${response.statusMessage}');
'Response => StatusCode: ${response.statusCode} ${response.statusMessage}');
Log.verbose('Response => Body ${response.data}');
Log.verbose('Headers => ${response.headers}');
return super.onResponse(response, handler);
Expand Down
4 changes: 2 additions & 2 deletions lib/app/core/services/api_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ApiConfig {
ApiConfig._internal();
static const String baseUrl = 'https://spark-dating-api.onrender.com/api/v1';

static const Duration receiveTimeout = Duration(milliseconds: 15000);
static const Duration connectionTimeout = Duration(milliseconds: 15000);
static const Duration receiveTimeout = Duration(milliseconds: 20000);
static const Duration connectionTimeout = Duration(milliseconds: 20000);
static const header = {
HttpHeaders.contentTypeHeader: 'application/json',
};
Expand Down
15 changes: 15 additions & 0 deletions lib/app/core/usecases/base_usecase.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:dartz/dartz.dart';
import 'package:equatable/equatable.dart';

import '../network/failures.dart';

abstract class BaseUseCase<T, Parameters> {
Future<Either<Failure, T>> call(Parameters parameters);
}

class NoParameters extends Equatable {
const NoParameters();

@override
List<Object?> get props => [];
}
2 changes: 1 addition & 1 deletion lib/bloc_observers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppBlocObserver extends BlocObserver {
Transition<dynamic, dynamic> transition,
) {
super.onTransition(bloc, transition);
// debugPrint('${bloc.runtimeType} $transition');
debugPrint('${bloc.runtimeType} $transition');
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/bloc_observers.dart';
import 'package:dating_app/firebase_options.dart';
import 'package:dating_app/injection_container.dart';
import 'package:dating_app/app/core/config/injection_container.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:dating_app/app/core/network/dio_client.dart';
import 'package:dating_app/injection_container.dart';
import 'package:dating_app/app/core/config/injection_container.dart';
import 'package:dating_app/src/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import 'package:dio/dio.dart';

Expand Down
50 changes: 22 additions & 28 deletions lib/src/auth/data/datasource/auth_remote_data_source.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import 'dart:convert';

import 'package:dating_app/injection_container.dart';
import 'package:dating_app/src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import 'package:dio/dio.dart';

import '../../../../app/core/network/dio_client.dart';
import '../../../../app/core/network/dio_interceptors.dart';
import '../../../../app/core/services/api_url.dart';

abstract class AuthRemoteDataSource {
Future<Response> createUser(SignupEvent event);
Future<Response> loginUser(LoginEvent event);
Future<Response> verifyOtp(VerifyOtpEvent event);
Future<Response> resendOtp(ResendOtpEvent event);
Future<Response> forgotPassword(ForgotPasswordEvent event);
Future<Response> resetPassword(ResetPasswordEvent event);
Future<Response> logoutUsers();
}

class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
final DioClient dioClient = serviceLocator<DioClient>();
class AuthRemoteDataSource {
AuthRemoteDataSource({Dio? dio})
: _dio = dio ?? Dio()
..interceptors.add(DioInterceptor())
..options.baseUrl = ApiConfig.baseUrl
..options.connectTimeout = ApiConfig.connectionTimeout
..options.receiveTimeout = ApiConfig.receiveTimeout
..options.sendTimeout = const Duration(milliseconds: 20000)
..options.baseUrl = ApiConfig.baseUrl
..options.headers = ApiConfig.header
..options.contentType = 'application/json; charset=utf-8'
..options.responseType = ResponseType.json;
final Dio _dio;

@override
Future<Response> createUser(SignupEvent event) async {
final register = {
'firstName': event.firstName,
Expand All @@ -28,78 +28,72 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
'password': event.password,
};
final data = jsonEncode(register);
return await dioClient.dio.post(
return await _dio.post(
'/auth/register',
data: data,
);
}

@override
Future<Response> loginUser(LoginEvent event) async {
final login = {
'email': event.email,
'password': event.password,
};
final data = jsonEncode(login);
return await dioClient.dio.post(
return await _dio.post(
'/auth/login',
data: data,
);
}

@override
Future<Response> verifyOtp(VerifyOtpEvent event) async {
final verifyOtp = {
'otp': event.otp,
'email': event.email,
};
final data = jsonEncode(verifyOtp);
return await dioClient.dio.post(
return await _dio.post(
'/auth/verifyOtp',
data: data,
);
}

@override
Future<Response> resendOtp(ResendOtpEvent event) async {
final resentOtp = {
'email': event.email,
};
final data = jsonEncode(resentOtp);
return await dioClient.dio.post(
return await _dio.post(
'/auth/resendOtp',
data: data,
);
}

@override
Future<Response> forgotPassword(ForgotPasswordEvent event) async {
final forgotData = {
'email': event.email,
};
final data = jsonEncode(forgotData);
return await dioClient.dio.post(
return await _dio.post(
'/auth/forgotPassword',
data: data,
);
}

@override
Future<Response> resetPassword(ResetPasswordEvent event) async {
final resetData = {
'otp': event.otp,
'password': event.password,
'email': event.email,
};
final data = jsonEncode(resetData);
return await dioClient.dio.post(
return await _dio.post(
'/auth/resetPassword',
data: data,
);
}

@override
Future<Response> logoutUsers() async {
return await dioClient.dio.post('/auth/logout');
return await _dio.post('/auth/logout');
}
}
10 changes: 3 additions & 7 deletions lib/src/auth/data/repository/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,25 @@ import 'package:dating_app/src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import '../../../../app/core/network/failures.dart';

class AuthRepositories {
AuthRepositories({AuthRemoteDataSourceImpl? authRemoteDataSourceImpl})
AuthRepositories({AuthRemoteDataSource? authRemoteDataSource})
: _authRemoteDataSourceImpl =
authRemoteDataSourceImpl ?? AuthRemoteDataSourceImpl();
final AuthRemoteDataSourceImpl _authRemoteDataSourceImpl;
authRemoteDataSource ?? AuthRemoteDataSource();
final AuthRemoteDataSource _authRemoteDataSourceImpl;

ResultFuture<LoginResponse> login(LoginEvent event) async {
try {
final response = await _authRemoteDataSourceImpl.loginUser(event);
return Right(LoginResponse.fromJson(response.data));
} on ServerFailure catch (e) {
Log.error('login error', e.message);
return Left(e);
}
}

ResultFuture<User> signup(SignupEvent event) async {
try {
final response = await _authRemoteDataSourceImpl.createUser(event);
Log.debug(response.data['user']);
return Right(User.fromJson(response.data['user']));
} on ServerFailure catch (e) {
Log.error('Signup error', e.message);
return Left(e);
}
}
Expand All @@ -42,7 +39,6 @@ class AuthRepositories {
debugPrint(response.data);
return Right(response.data['message']);
} on ServerFailure catch (e) {
Log.error('Verify Otp error', e.message);
return Left(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _CompleteOTPVerificationView extends StatelessView<
text: 'Verifcation successful',
style: appMStyle(26, Color(kDark.value), FontWeight.w600),
),
20.sbH,
20.sbh,
Container(
alignment: Alignment.center,
width: width * 0.2,
Expand All @@ -28,7 +28,7 @@ class _CompleteOTPVerificationView extends StatelessView<
),
child: Icon(Icons.done, color: Color(kLight.value), size: 50.w),
),
20.sbH,
20.sbh,
CustomButton(
width: width,
height: height / 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class ForgotPasswordController extends State<ForgotPasswordScreen> {
context.pushNamed(ResetPasswordScreen.name, extra: emailController.text);
}

resetError(Failure error) {
resetError(String error) {
Fluttertoast.showToast(
msg: error.toString(),
msg: error,
backgroundColor: Color(kDarkRed.value),
);
}
Expand Down
Loading

0 comments on commit c6fc591

Please sign in to comment.