Skip to content

Commit

Permalink
adding notification feature 🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
olawills committed Sep 22, 2023
1 parent 18be25f commit 5982170
Show file tree
Hide file tree
Showing 25 changed files with 260 additions and 124 deletions.
5 changes: 5 additions & 0 deletions lib/app/common/constants/app_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ class AppString {
static const socketException =
'Check your internet connection, then refresh the page';
static const connectionMessage = 'No Internet Connection';

// Skeletons Strings
static String notificationMsg = 'We think $matchMsg';
static String matchMsg = 'Vicky Johnson';
static String lastMsg = 'is a perfect match for you';
}
1 change: 1 addition & 0 deletions lib/app/common/utils/asset_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Assets {
static String svgHelper(String image) => 'assets/icons/$image.svg';
static String noInternetImage = 'assets/images/no-wifi.png';
static String noAccountImage = 'assets/images/no-account.png';
static String heartMached = 'assets/icons/broken_heart.svg';
}

class AppIcons {
Expand Down
4 changes: 2 additions & 2 deletions lib/app/common/widgets/custom_btn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../core/core.dart';

class CustomBtn extends StatelessWidget {
const CustomBtn({
class CustomButton extends StatelessWidget {
const CustomButton({
super.key,
this.width,
this.height,
Expand Down
15 changes: 12 additions & 3 deletions lib/app/common/widgets/display_pic_widget.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import 'package:dating_app/app/common/constants/color_style.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../core/core.dart';

class UserDisplayPicture extends StatelessWidget {
final Function()? onTap;
final String imageUrl;
const UserDisplayPicture({super.key, this.onTap, required this.imageUrl});
final double? largeDP;
final bool isLargeDp;
const UserDisplayPicture({
super.key,
this.onTap,
required this.imageUrl,
this.largeDP,
this.isLargeDp = false,
});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: CircleAvatar(
radius: 20,
radius: isLargeDp ? 80.r : 20.r,
backgroundColor: Color(kDarkRed.value),
child: CircleAvatar(
radius: 18,
radius: isLargeDp ? 76.r : 18.r,
backgroundImage: AssetImage(imageUrl),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/app/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export '../../../presentation/auth/presentation/views/otp_verification/otp_barre
export '../../../presentation/auth/presentation/views/signup/barrels.dart';
export '../../../presentation/features/presentation/cubit/internet_connection/internet_connection_cubit.dart';
export '../../../presentation/features/presentation/views/chats/chats_barrel.dart';
export '../../../presentation/features/presentation/views/features_controller.dart';
export '../../presentation/features/presentation/views/skeleton_controller.dart';
export '../../../presentation/features/presentation/views/home/home_barrel.dart';
export '../../../presentation/features/presentation/views/notification/notification_barrel.dart';
export '../../../presentation/features/presentation/views/profile/profile_barrel.dart';
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
Expand Up @@ -33,6 +33,6 @@ class AppBlocProviders {
// Internet Connection Cubit
BlocProvider<InternetConnectionCubit>(
create: (context) =>
serviceLocator<InternetConnectionCubit>()..init())
serviceLocator<InternetConnectionCubit>())
];
}
32 changes: 5 additions & 27 deletions lib/app/core/routes/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,8 @@ final GoRouter _router = GoRouter(
),
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) {
// return BlocListener<InternetConnectionCubit, InternetConnectionState>(
// listener: (context, state) {
// if (state is InternetDisconnected) {
// InternetConnectionCubit.get(context).showDialog = true;
// Log.debug('No Internet');
// Future.delayed(const Duration(milliseconds: 500), () {
// Fluttertoast.showToast(
// msg: 'No Internet Connection',
// fontSize: 16,
// backgroundColor: Color(kDarkRed.value),
// gravity: ToastGravity.TOP);
// });
// }
// if (state is InternetConnected) {
// if (InternetConnectionCubit.get(context).showDialog) {
// Log.debug(' Internet');
// InternetConnectionCubit.get(context).showDialog = false;
// }
// }
// },
return FeaturesScreen(child: child);
// );
},
pageBuilder: (context, state, child) =>
NoTransitionPage(child: SkeletonScreen(child: child)),
routes: [
GoRoute(
path: HomeScreen.path,
Expand All @@ -160,10 +138,10 @@ final GoRouter _router = GoRouter(
return const NoTransitionPage(child: HomeScreen());
}),
GoRoute(
path: ChatsScreen.route,
name: ChatsScreen.name,
path: ChatTabBarSkeleton.path,
name: ChatTabBarSkeleton.name,
pageBuilder: (context, state) =>
const NoTransitionPage(child: ChatsScreen()),
const NoTransitionPage(child: ChatTabBarSkeleton()),
),
GoRoute(
path: NotificationScreen.route,
Expand Down
6 changes: 5 additions & 1 deletion lib/injection_container.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/presentation/auth/data/datasource/auth_info_remote_datasource.dart';
import 'package:dating_app/presentation/auth/data/datasource/auth_remote_data_source.dart';
Expand All @@ -14,6 +15,7 @@ import 'package:get_it/get_it.dart';
import 'app/core/network_handler/dio_client.dart';
import 'presentation/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import 'presentation/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import 'presentation/features/data/repository/user_repository.dart';

GetIt serviceLocator = GetIt.instance;

Expand All @@ -31,7 +33,7 @@ class ServiceLocator {
serviceLocator
.registerFactory<BottomNavigationCubit>(() => BottomNavigationCubit());
serviceLocator.registerFactory<InternetConnectionCubit>(
() => InternetConnectionCubit()..init());
() => InternetConnectionCubit(connectivity: serviceLocator()));

// Data Source
serviceLocator.registerFactory<AuthRemoteDataSource>(
Expand All @@ -45,10 +47,12 @@ class ServiceLocator {
serviceLocator.registerFactory<AuthRepositories>(() => AuthRepositories());
serviceLocator
.registerFactory<AuthInfoRepository>(() => AuthInfoRepository());
serviceLocator.registerFactory<UserRepository>(() => UserRepository());

// Dio
serviceLocator.registerLazySingleton<DioClient>(
() => DioClient(serviceLocator<Dio>()));
serviceLocator.registerLazySingleton<Dio>(() => Dio());
serviceLocator.registerLazySingleton<Connectivity>(() => Connectivity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _CompleteOTPVerificationView extends StatelessView<
child: Icon(Icons.done, color: Color(kLight.value), size: 50.w),
),
20.sbH,
CustomBtn(
CustomButton(
width: width,
height: height / 15,
color: Color(kDarkRed.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ class _ForgotPasswordView
prefix: const Icon(Icons.person),
keyboardType: TextInputType.emailAddress,
textEditingController: controller.emailController,
validator: (val) =>
Validator().isEmail().lengthGreaterThan(8).validate(val),
validator: (val) => Validators.emailValidator(value: val),
),
20.sbH,
BlocBuilder<AuthBloc, AuthenticationState>(
builder: (context, state) {
return CustomBtn(
return CustomButton(
width: width,
height: height / 15,
color: Color(kDarkRed.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class _InforView extends StatelessView<InfoScreen, InfoController> {
),
),
70.sbH,
CustomBtn(
CustomButton(
width: width,
height: height / 15,
color: Color(kDarkRed.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class _InterestView extends StatelessView<InterestScreen, InterestController> {
}
},
builder: (context, state) {
return CustomBtn(
return CustomButton(
width: width,
height: height / 15,
color: Color(kDarkRed.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class _LoginView extends StatelessView<LoginScreen, LoginController> {
keyboardType: TextInputType.emailAddress,
textEditingController: controller.emailController,
isValidationMessage: true,
validator: (val) => Validator()
.isEmail()
.lengthGreaterThan(8)
.validate(val),
validator: (val) => Validators.emailValidator(value: val),
),
CustomTxtField(
labelText: 'Password',
Expand All @@ -49,10 +46,8 @@ class _LoginView extends StatelessView<LoginScreen, LoginController> {
suffix: true,
textEditingController: controller.passwordController,
isValidationMessage: true,
validator: (val) => Validator()
.isPassword()
.lengthGreaterThan(6)
.validate(val),
validator: (val) =>
Validators.passwordValidator(value: val),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down Expand Up @@ -86,7 +81,7 @@ class _LoginView extends StatelessView<LoginScreen, LoginController> {
30.sbH,
BlocBuilder<AuthBloc, AuthenticationState>(
builder: (context, state) {
return CustomBtn(
return CustomButton(
width: width,
height: height / 15,
color: Color(kDarkRed.value),
Expand Down Expand Up @@ -153,7 +148,8 @@ class _LoginView extends StatelessView<LoginScreen, LoginController> {
),
),
],
).padding(const EdgeInsets.symmetric(vertical: 30, horizontal: 10)),
).padding(
const EdgeInsets.symmetric(vertical: 30, horizontal: 10)),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _OtpView extends StatelessView<OtpScreen, OtpController> {
BlocBuilder<AuthBloc, AuthenticationState>(
builder: (context, state) {
return Center(
child: CustomBtn(
child: CustomButton(
width: width * 0.4,
height: height / 15,
color: Color(kDarkRed.value),
Expand All @@ -90,7 +90,8 @@ class _OtpView extends StatelessView<OtpScreen, OtpController> {
},
),
],
).padding(const EdgeInsets.symmetric(horizontal: 18, vertical: 20)),
).padding(
const EdgeInsets.symmetric(horizontal: 18, vertical: 20)),
AppKeyBoard(controller: controller.otpController)
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class _SignUpView extends StatelessView<SignUpScreen, SignupController> {
50.sbH,
BlocBuilder<AuthBloc, AuthenticationState>(
builder: (context, state) {
return CustomBtn(
return CustomButton(
width: width,
height: height / 15,
color: Color(kDarkRed.value),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

part 'internet_connection_state.dart';

class InternetConnectionCubit extends Cubit<InternetConnectionState> {
InternetConnectionCubit() : super(CheckConnectionLoading());

static InternetConnectionCubit get(context) => BlocProvider.of(context);

final _connectivity = Connectivity();
bool? hasConnection;

Future<void> init() async {
_connectivity.onConnectivityChanged.listen(_connectionChange);
_checkConnection(await _connectivity.checkConnectivity());
}

void _connectionChange(ConnectivityResult result) {
_checkConnection(result);
}

Future<bool?> _checkConnection(ConnectivityResult result) async {
bool? previousConnection;

if (hasConnection != null) previousConnection = hasConnection;

if (result == ConnectivityResult.none) {
hasConnection = false;
if (previousConnection != hasConnection) {
_connectionChangeController(hasConnection!);
final Connectivity connectivity;
late StreamSubscription connectivityStreamSubscription;

InternetConnectionCubit({required this.connectivity})
: super(InternetLoading()) {
connectivityStreamSubscription =
connectivity.onConnectivityChanged.listen((connectivityResult) {
if (connectivityResult == ConnectivityResult.wifi) {
emitInternetConnected(ConnectionType.wifi);
} else if (connectivityResult == ConnectivityResult.mobile) {
emitInternetConnected(ConnectionType.mobile);
} else if (connectivityResult == ConnectivityResult.none) {
emitInternetDisconnected();
}
return hasConnection;
}
return hasConnection;
});
}

bool showDialog = false;
void emitInternetConnected(ConnectionType connectionType) =>
emit(InternetConnected(connectionType: connectionType));

void emitInternetDisconnected() => emit(InternetDisconnected());

void _connectionChangeController(bool hasConnection) {
if (hasConnection) {
emit(InternetConnected());
} else {
emit(InternetDisconnected());
}
@override
Future<void> close() {
connectivityStreamSubscription.cancel();
return super.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
part of 'internet_connection_cubit.dart';

enum ConnectionType {
wifi,
mobile,
}

abstract class InternetConnectionState {}

class CheckConnectionLoading extends InternetConnectionState {}
class InternetLoading extends InternetConnectionState {}

class InternetConnected extends InternetConnectionState {}
class InternetConnected extends InternetConnectionState {
final ConnectionType connectionType;

class InternetDisconnected extends InternetConnectionState {}
InternetConnected({required this.connectionType});
}

class UnknownInternetError extends InternetConnectionState {}
class InternetDisconnected extends InternetConnectionState {}
Loading

0 comments on commit 5982170

Please sign in to comment.