Skip to content

Commit

Permalink
last version
Browse files Browse the repository at this point in the history
  • Loading branch information
arda-copur committed Aug 19, 2024
1 parent 1cf57c9 commit f032b77
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

#bash
.env
Binary file added flutter_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 3 additions & 8 deletions lib/feature/services/auth/user_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';

class UserAuth {

Future<void> registerUser(String name, String email, String password,
String homeCode, String? imageUrl,context) async {
String homeCode, String? imageUrl, context) async {
try {
DocumentSnapshot homeDoc = await FirebaseFirestore.instance
.collection('homes')
.doc(homeCode)
.get();



// Proceed with registration if homeCode does not exist
UserCredential userCredential =
await FirebaseAuth.instance.createUserWithEmailAndPassword(
Expand Down Expand Up @@ -42,9 +39,7 @@ class UserAuth {
}
}



Future<void> loginUser(String email, String password,context) async {
Future<void> loginUser(String email, String password, context) async {
try {
UserCredential userCredential =
await FirebaseAuth.instance.signInWithEmailAndPassword(
Expand All @@ -58,4 +53,4 @@ class UserAuth {
print("Error: $e");
}
}
}
}
55 changes: 42 additions & 13 deletions lib/feature/services/one_signal.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import 'dart:convert';

import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
import 'package:http/http.dart' as http;

class OneSignalManager {
final oneSignalAppId = dotenv.env['ONESIGNAL_APP_ID'] ?? 'default-value';

void connection() {
OneSignal.initialize("a45dd3f7-4937-4f9c-98ee-561c0604ec06");
OneSignal.Debug.setLogLevel(OSLogLevel.none);
}

OneSignal.initialize(oneSignalAppId);
OneSignal.Debug.setLogLevel(OSLogLevel.none);
}

static void get login async {
var userId = 'unique userId';
// Bir kullanıcının OneSignal SDK'ya giriş yapması,
// kullanıcı bağlamını söz konusu kullanıcıya değiştirecektir.
// OneSignal tarafında externalId ile cihaz eşleştirmesi yapılarak
// kullanıcıya özel bildirim gönderirken bu değer ile özel bildirim
// gönderebiliriz.
await OneSignal.login(userId);
}

Expand All @@ -26,14 +25,44 @@ class OneSignalManager {
await OneSignal.Debug.setLogLevel(OSLogLevel.none);
OneSignal.initialize("YOUR APP ID");
login;
// Bildirim izni yoksa kullanıcıdan bildirim izni alıyoruz
await OneSignal.Notifications.requestPermission(true).then((accepted) {});
}

static get onClick {
OneSignal.Notifications.addClickListener((OSNotificationClickEvent result) async {
// Bildirime tıkladığında yapılacak işlemleri burada gerçekleştiriyoruz
OneSignal.Notifications.addClickListener(
(OSNotificationClickEvent result) async {
print('notification onClick');
});
}
}

final String oneSignalApiKey = 'YOUR_ONESIGNAL_API_KEY';

Future<void> sendNotification(String playerId) async {
final url = 'https://onesignal.com/api/v1/notifications';
final headers = {
'Authorization': 'Basic $oneSignalApiKey',
'Content-Type': 'application/json'
};
final body = jsonEncode({
'app_id': oneSignalAppId,
'include_player_ids': [playerId],
'contents': {'en': 'You have successfully logged in!'},
'headings': {'en': 'Login Notification'}
});

try {
final response =
await http.post(Uri.parse(url), headers: headers, body: body);
if (response.statusCode == 200) {
print('Notification sent successfully');
print('Response: ${response.body}');
} else {
print('Failed to send notification');
print('Status Code: ${response.statusCode}');
print('Response: ${response.body}');
}
} catch (e) {
print('Error sending notification: $e');
}
}
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import 'package:fam_works/feature/utils/app_routes.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:provider/provider.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await dotenv.load();
OneSignalManager().connection();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
runApp(
Expand Down
40 changes: 40 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.2.0"
archive:
dependency: transitive
description:
name: archive
sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d
url: "https://pub.dev"
source: hosted
version: "3.6.1"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -153,6 +161,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
cli_util:
dependency: transitive
description:
name: cli_util
sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19
url: "https://pub.dev"
source: hosted
version: "0.4.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -430,6 +446,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.3.1"
flutter_dotenv:
dependency: "direct main"
description:
name: flutter_dotenv
sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
flutter_launcher_icons:
dependency: "direct main"
description:
name: flutter_launcher_icons
sha256: "526faf84284b86a4cb36d20a5e45147747b7563d921373d4ee0559c54fcdbcea"
url: "https://pub.dev"
source: hosted
version: "0.13.1"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -584,6 +616,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
image:
dependency: transitive
description:
name: image
sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8"
url: "https://pub.dev"
source: hosted
version: "4.2.0"
image_picker:
dependency: "direct main"
description:
Expand Down
9 changes: 6 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies:
delightful_toast: ^1.1.0
flutter_rating_bar: ^4.0.1
flutter_map: ^6.1.0
flutter_launcher_icons: ^0.13.1
#Cache
shared_preferences: ^2.2.0
cached_network_image: ^3.3.1
Expand All @@ -41,6 +42,8 @@ dependencies:
geolocator: ^11.0.0
#Notification
onesignal_flutter: ^5.1.2
#Security
flutter_dotenv: ^5.1.0



Expand All @@ -63,6 +66,6 @@ flutter:
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- assets/
- .env

0 comments on commit f032b77

Please sign in to comment.