1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Workmanager inputData is null when trying to retrieve in background task Flutter

Discussão em 'Mobile' iniciado por Stack, Outubro 16, 2024 às 10:22.

  1. Stack

    Stack Membro Participativo

    I'm having trouble passing and retrieving inputData in Flutter's Workmanager. I'm trying to send some data (like id and date) when registering a task, but when I try to access the inputData in the background task, I keep getting null.

    Workmanager().registerOneOffTask(
    "simpleTask", // Unique task name
    "simpleTask", // The task name
    tag: '1',
    inputData: {'id': '1', 'date': '16-10-2024'}, // Input data to be passed
    );

    void callbackDispatcher() {
    Workmanager().executeTask((task, inputData) {
    print('Task name: $task');
    print('Input data: $inputData'); // This prints null
    print('Notification id: ${inputData?["id"]}');
    print('Notification date: ${inputData?["date"]}');
    return Future.value(true);
    });
    }

    Workmanager().initialize(
    callbackDispatcher,
    isInDebugMode: true // For debugging
    );


    [​IMG]

    Continue reading...

Compartilhe esta Página