Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть How can I keep a variable value inside an isolate/FlutterBackgroundService?

  • Emrah KAYA
  • 2024-10-25
  • 9
How can I keep a variable value inside an isolate/FlutterBackgroundService?
  • ok logo

Скачать How can I keep a variable value inside an isolate/FlutterBackgroundService? бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно How can I keep a variable value inside an isolate/FlutterBackgroundService? или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку How can I keep a variable value inside an isolate/FlutterBackgroundService? бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео How can I keep a variable value inside an isolate/FlutterBackgroundService?

Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram:   / ky.emrah  

Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!How can I keep a variable value inside an isolate/FlutterBackgroundService?

I'm currently working on implementing an isolate with a notification handler in Flutter.
Flutter
It's already working, I have a MQTT listener that shows a notification using AwesomeNotification with 2 actions for accepting or rejecting the notification.
MQTT
AwesomeNotification
When a notification is accepted, I want to make an API call to update the record related to that notification.
To make it a bit easy for me, I included some details with the MQTT payload that I need to use to make the API call, I set that detail to a variable so I can use it later on.
MQTT
The problem is that when the app reaches AwesomeNotification's onActionReceivedMethod, the variable's value is already gone.
AwesomeNotification's onActionReceivedMethod
I think the reason for this is because, down the line, the executing code is already outside the scope of the service/isolate so the variable can't be reached already.
service/isolate
I then tried to use SharedPreferences, but a key doesn't get updated as fast as I wanted/expected it to be. Now, I'm at a loss as to how I could keep a bit of value around so I could proceed with the process.
SharedPreferences
Here's my current code:
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:isolate';
import 'dart:ui';

import 'package:baraco_frontend/helpers/api/request_vehicle_change_api_helper.dart';
import 'package:baraco_frontend/helpers/sharedPref/shared_pref_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:intl/intl.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:vibration/vibration.dart';
import 'package:awesome_notifications/awesome_notifications.dart';

import '../globals.dart';
import '../models/user.dart';
import 'mqtt_helper.dart';

final _service = FlutterBackgroundService();
String notifTxt = 'Waiting for notification';
const String approveKey = 'approve';
const String rejectKey = 'reject';
const String approveLabel = 'Approve';
const String rejectLabel = 'Reject';
String _requestVehicleChangeId = '';
ReceivePort processRequestVehicleChangeRecvPort = ReceivePort('processRequestVehicleChangeRecv');

Future void initializeService() async{
log('initializeService');
await _service.configure(
androidConfiguration: AndroidConfiguration(
autoStart: true,
onStart: _onServiceStart,
isForegroundMode: true,
),
iosConfiguration: IosConfiguration(
autoStart: true,
onForeground: _onServiceStart,
onBackground: _onServiceIosBackground,
),
);

await initializeLocalNotifications();
await initializeIsolateReceivePort();
startListeningNotificationEvents();
}

@pragma('vm:entry-point')
Future void _onServiceStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized();
log('service started');

if (service is AndroidServiceInstance) {
service.on('setAsForeground').listen((ev) {
service.setAsForegroundService();
});
service.on('setAsBackground').listen((ev) {
service.setAsBackgroundService();
});
}

service.on('stopService').listen((ev) {
service.stopSelf();
});

MqttHelper().connect().then((val) async {
var user = User.fromJson( jsonDecode(await SharedPrefHelper().getPrefWithKey( Globals.USER_PREF_KEY )) );

MqttHelper().send('hi from the app', user.mqttClientId);
MSource of the question:
https://stackoverflow.com/questions/7...

Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]