flutterbackendless

Flutter How to import backendless_sdk messaging module?


I am following this article How to Create a Chat App with Backendless SDK for Flutter

import 'package:flutter/material.dart';
import 'package:backendless_sdk/backendless_sdk.dart'; 
import 'package:backendless_sdk/src/modules/modules.dart';

There is a error:

"Target of URI doesn't exist: 'package:backendless_sdk/src/modules/modules.dart'."

The modules.dart import is required for Backendless.Messaging, but without the import there is an error:

The getter 'Messaging' isn't defined for the type 'Backendless'.

  void initListeners() async {
    Channel channel = await Backendless.Messaging.subscribe("myChannel");
    channel.addMessageListener(onMessageReceived);
  }

pub spec.yaml

dependencies:
  flutter:
    sdk: flutter
  backendless_sdk: ^1.1.8

How can I import the Messaging module?


Solution

  • You should change from:

    await Backendless.Messaging.subscribe
    

    in to:

    await Backendless.messaging.subscribe
                      ^
                      |
               small "m" here
    

    Versions

    I checked backendless_sdk: ^0.0.2 (from tutorial) and backendless_sdk: ^1.1.8 (newest one), and in both cases this field was named messaging (lowercase).

    Class Backendless

    backendless_sdk-1.1.8/lib/src/backendless.dart:

    enter image description here