Skip to content

Commit

Permalink
going public ☁️ 😃
Browse files Browse the repository at this point in the history
  • Loading branch information
olawills committed Sep 27, 2023
1 parent 29bead6 commit 6ff8dc8
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/app/common/constants/app_constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Duration veryLongDuration = Duration(seconds: 3);
const profileUrl =
"https://media.istockphoto.com/id/1451587807/vector/user-profile-icon-vector-avatar-or-person-icon-profile-picture-portrait-symbol-vector.jpg?s=612x612&w=0&k=20&c=yDJ4ITX1cHMh25Lt1vI1zBn2cAKKAlByHBvPJ8gEiIg=";

String kAppName = 'Dating App';
String kAppName = 'Sparkz Dating App';
String firstPage = 'Find your';

String pageOne =
Expand Down
20 changes: 19 additions & 1 deletion lib/app/core/domain/dating_app.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:dating_app/app/common/common.dart';
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/app/core/routes/app_router.dart';
import 'package:dating_app/app/core/services/push_notification.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SparkzConfig extends StatelessWidget {
class SparkzConfig extends StatefulWidget {
const SparkzConfig({super.key});

@override
State<SparkzConfig> createState() => _SparkzConfigState();
}

class _SparkzConfigState extends State<SparkzConfig> {
@override
void initState() {
super.initState();

// ** Initialize Push Notifications
FirebasePushNotificationServce.getDeviceToken();
FirebasePushNotificationServce.requestPermission();
FirebasePushNotificationServce.initializeNotification();
AwesomeNotifications().requestPermissionToSendNotifications();
}

@override
Widget build(BuildContext context) {
return GestureDetector(
Expand Down
3 changes: 2 additions & 1 deletion lib/app/core/services/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# api_url.dart
api_url.dart
app_tokens.dart
19 changes: 16 additions & 3 deletions lib/app/core/services/app_tokens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ class AppTokens {
static String hasSeenOnboardingKey = 'hasSeenOnboardingKey';
static String authToken = 'auth_token';
static String infoToken = 'info_token';
static String userDetails = 'users';
static String fistName = 'firstName';
// static String userDetails = 'users';
// static String fistName = 'firstName';
// static String lastName = 'lastName';
// static String userEmail = 'email';

static String firstName = 'firstName';
static String lastName = 'lastName';
static String userEmail = 'email';
static String email = 'email';
static String loggedIn = 'auth_token';
static String firstTime = 'FirstTime';
static String userDetails = 'user_data';
static String gender = 'gender';
static String interest = 'interest';
static String profilePicture = 'ProfilePicture';
static String finishedOtp = '';
static String token = 'access_token';
static String pushNotificationToken = "FCM";
}
24 changes: 13 additions & 11 deletions lib/app/core/services/auth_local_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:dating_app/app/common/common.dart';
import 'package:dating_app/presentation/auth/data/models/user.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'app_tokens.dart';

class LocalDataStorage {
static final LocalDataStorage instance = LocalDataStorage._init();
static SharedPreferences? _prefs;
Expand All @@ -13,18 +15,18 @@ class LocalDataStorage {
return _prefs!;
}

final String _firstName = 'firstName';
final String _lastName = 'lastName';
final String _email = 'email';
final String _loggedIn = 'auth_token';
final String _firstTime = 'FirstTime';
final _userDetails = 'user_data';
final String _gender = 'gender';
final String _interest = 'interest';
final String _profilePicture = 'ProfilePicture';
final String _firstName = AppTokens.firstName;
final String _lastName = AppTokens.lastName;
final String _email = AppTokens.email;
final String _loggedIn = AppTokens.loggedIn;
final String _firstTime = AppTokens.firstTime;
final _userDetails = AppTokens.userDetails;
final String _gender = AppTokens.gender;
final String _interest = AppTokens.gender;
final String _profilePicture = AppTokens.profilePicture;
final String _finishedOtp = '';
final String _token = 'access_token';
final String _pushNotificationToken = "FCM";
final String _token = AppTokens.token;
final String _pushNotificationToken = AppTokens.pushNotificationToken;

Future<bool> setFirstTime() async {
final pref = await instance.prefs;
Expand Down
56 changes: 55 additions & 1 deletion lib/app/core/services/push_notification.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:dating_app/app/core/logger/app_logger.dart';
import 'package:dating_app/app/core/services/auth_local_data_source.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
Expand All @@ -6,11 +8,63 @@ class FirebasePushNotificationServce {
FirebasePushNotificationServce._();
static FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;

static void init() {
static void getDeviceToken() {
// ** get notification token
firebaseMessaging.getToken().then((value) async {
debugPrint("getToken :$value");
await LocalDataStorage.instance.saveNotificationMessage(value!);
});
}

static Future<void> initializeNotification() async {
AwesomeNotifications().initialize(
null,
[
NotificationChannel(
channelKey: "Sparkz Dating App",
channelName: "Sparkz Dating App",
channelDescription: "Notification channel for Sparkz Dating App",
importance: NotificationImportance.High,
icon: 'resource://drawable/background.png'),
],
);
}

static Future<void> onMessageListen() async {
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
Log.info("....................................onMessage..........");
Log.info(
"onMessage: ${message.notification?.title}/${message.notification?.body}");

await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 0,
channelKey: "Sparks Dating App",
title: message.notification?.title,
body: message.notification?.body,
largeIcon: "asset://assets/images/no-wifi.png",
),
);
});
}

static Future<void> requestPermission() async {
NotificationSettings settings = await firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
debugPrint("User have granted permission");
} else if (settings.authorizationStatus ==
AuthorizationStatus.provisional) {
debugPrint("User has granted provisional permission");
} else {
debugPrint("User has not acepted any permission");
}
}
}
15 changes: 9 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';

import 'app/core/domain/all_blocs.dart';
import 'app/core/domain/dating_app.dart';
import 'app/core/services/push_notification.dart';

Future<void> _fiebaseMessagingBackgroundHandler(RemoteMessage message) async {
debugPrint("Handling background message:${message.messageId}");
}

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

// ** Initialize Push Notifications
FirebasePushNotificationServce.init();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await FirebaseMessaging.instance.getInitialMessage();
FirebaseMessaging.onBackgroundMessage(_fiebaseMessagingBackgroundHandler);

Bloc.observer = AppBlocObserver();

ServiceLocator.init();
runApp(
MultiBlocProvider(
Expand Down
11 changes: 4 additions & 7 deletions lib/presentation/auth/data/repository/auth_repository.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dartz/dartz.dart';
import 'package:dating_app/app/common/common.dart';
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/app/core/logger/app_logger.dart';
import 'package:dating_app/app/core/network_handler/dio_exception.dart';
import 'package:dating_app/app/core/network_handler/failures.dart';
Expand All @@ -21,10 +22,9 @@ class AuthRepositories {
return Right(LoginResponse.fromJson(response.data));
} on DioException catch (failure) {
Log.error('login error', failure.type);
final errorMessage = DioExceptions.fromDioError(failure).toString();
return failure.type == DioExceptionType.badResponse
? Left(ServerFailure(message: failure.message.toString()))
: Left(ServerFailure(message: errorMessage));
: Left(ServerFailure(message: failure.response!.data['message']));
} catch (e) {
return Left(GeneralFailure(message: e.toString()));
}
Expand All @@ -38,19 +38,16 @@ class AuthRepositories {
} on DioException catch (failure) {
Log.error('Signup error', failure.type);
Log.debug(failure.message);
final errorMessage = DioExceptions.fromDioError(failure);
return failure.type == DioExceptionType.badResponse
? Left(ServerFailure(message: failure.message.toString()))
: Left(ApiFailure.fromException(errorMessage));
} catch (e) {
return Left(GeneralFailure(message: e.toString()));
: Left(GeneralFailure(message: failure.response!.data['message']));
}
}

ResultFuture<String> verifyOtp(VerifyOtpEvent event) async {
try {
final response = await _authRemoteDataSourceImpl.verifyOtp(event);
print(response.data);
debugPrint(response.data);
return Right(response.data['message'].toString());
} on DioException catch (failure) {
Log.error('Signup error', failure.type);
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <awesome_notifications/awesome_notifications_plugin.h>
#include <smart_auth/smart_auth_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) awesome_notifications_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AwesomeNotificationsPlugin");
awesome_notifications_plugin_register_with_registrar(awesome_notifications_registrar);
g_autoptr(FlPluginRegistrar) smart_auth_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SmartAuthPlugin");
smart_auth_plugin_register_with_registrar(smart_auth_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
awesome_notifications
smart_auth
)

Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import FlutterMacOS
import Foundation

import awesome_notifications
import connectivity_plus
import firebase_core
import firebase_messaging
Expand All @@ -15,6 +16,7 @@ import smart_auth
import sqflite

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AwesomeNotificationsPlugin.register(with: registry.registrar(forPlugin: "AwesomeNotificationsPlugin"))
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin"))
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
awesome_notifications:
dependency: "direct main"
description:
name: awesome_notifications
sha256: "2b430c75cc879d6cfd52bb6eb2b5c1591ed425347816408cdcbd3f6916bba14c"
url: "https://pub.dev"
source: hosted
version: "0.7.4+1"
bloc:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ environment:
sdk: ">=3.0.5 <4.0.0"

dependencies:
awesome_notifications: ^0.7.4+1
bloc: ^8.1.1
cached_network_image: ^3.2.3
carousel_slider: ^4.2.1
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

#include "generated_plugin_registrant.h"

#include <awesome_notifications/awesome_notifications_plugin_c_api.h>
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <smart_auth/smart_auth_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AwesomeNotificationsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AwesomeNotificationsPluginCApi"));
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
FirebaseCorePluginCApiRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
awesome_notifications
connectivity_plus
firebase_core
smart_auth
Expand Down

0 comments on commit 6ff8dc8

Please sign in to comment.