first commit
This commit is contained in:
115
lib/controller/notification_controller.dart
Normal file
115
lib/controller/notification_controller.dart
Normal file
@@ -0,0 +1,115 @@
|
||||
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().getAllTokenDrivers();
|
||||
}
|
||||
|
||||
getTokensPassengers() async {
|
||||
await FirebaseMessagesController().getAllTokenPassengers();
|
||||
}
|
||||
|
||||
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++) {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}),
|
||||
cancel: MyElevatedButton(
|
||||
title: 'cancel',
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user