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(); final title = TextEditingController(); final body = TextEditingController(); List tokensDriver = []; List tokensPassengers = []; getTokensDrivers() async { await FirebaseMessagesController().loadAllPagesAndSendNotifications(); } getTokensPassengers() async { await FirebaseMessagesController() .loadAllPagesAndSendNotificationsPassengers(); } Future 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 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(); })); } }