Files
tripz_admin/lib/controller/notification_controller.dart
Hamza-Ayed 9022941e18 9/1/1
2024-09-01 17:45:48 +03:00

118 lines
3.9 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:sefer_admin1/constant/box_name.dart';
import 'package:sefer_admin1/controller/firebase/firbase_messge.dart';
import 'package:sefer_admin1/main.dart';
import 'package:sefer_admin1/views/widgets/elevated_btn.dart';
import 'package:sefer_admin1/views/widgets/my_textField.dart';
import '../constant/style.dart';
class NotificationController extends GetxController {
final formKey = GlobalKey<FormState>();
final title = TextEditingController();
final body = TextEditingController();
List<String> tokensDriver = [];
List<String> tokensPassengers = [];
getTokensDrivers() async {
await FirebaseMessagesController().loadAllPagesAndSendNotifications();
}
getTokensPassengers() async {
await FirebaseMessagesController()
.loadAllPagesAndSendNotificationsPassengers();
}
Future<dynamic> sendNotificationDrivers() {
return Get.defaultDialog(
title: 'send notification'.tr,
titleStyle: AppStyle.title,
content: Form(
key: formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: MyTextForm(
controller: title,
label: 'title notification'.tr,
hint: 'title notification'.tr,
type: TextInputType.name),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: MyTextForm(
controller: body,
label: 'body notification'.tr,
hint: 'body notification'.tr,
type: TextInputType.name),
),
],
),
),
confirm: MyElevatedButton(
title: 'send'.tr,
onPressed: () async {
tokensDriver = box.read(BoxName.tokensDrivers);
if (formKey.currentState!.validate()) {
for (var i = 0; i < tokensDriver.length; i++) {
print(tokensDriver.length);
// FirebaseMessagesController().sendNotificationToAnyWithoutData(
// title.text, body.text, tokensDriver[i]);
}
}
}),
cancel: MyElevatedButton(
title: 'cancel',
onPressed: () {
Get.back();
}));
}
Future<dynamic> sendNotificationPassengers() {
return Get.defaultDialog(
title: 'send notification'.tr,
titleStyle: AppStyle.title,
content: Form(
key: formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: MyTextForm(
controller: title,
label: 'title notification'.tr,
hint: 'title notification'.tr,
type: TextInputType.name),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: MyTextForm(
controller: body,
label: 'body notification'.tr,
hint: 'body notification'.tr,
type: TextInputType.name),
),
],
),
),
confirm: MyElevatedButton(
title: 'send'.tr,
onPressed: () async {
tokensPassengers = box.read(BoxName.tokensPassengers);
for (var i = 0; i < tokensPassengers.length; i++) {
if (formKey.currentState!.validate()) {
FirebaseMessagesController().sendNotificationToAnyWithoutData(
title.text, body.text, tokensPassengers[i], 'order.wav');
}
}
}),
cancel: MyElevatedButton(
title: 'cancel',
onPressed: () {
Get.back();
}));
}
}