Flutter How to import backendless_sdk messaging module?

229 Views Asked by At

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?

3

There are 3 best solutions below

1
Boken On BEST ANSWER

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

6
Haniel Baez On

It look like you are missing the installation step.

  • From the terminal: Run flutter pub get.

OR

  • From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec.yaml.
  • From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec.yaml.
1
Mark Piller On

I do not see any references to modules.dart in the article you mentioned. You need to import backendless_sdk and also include the socket.io dependency:

dependencies {
   implementation ('io.socket:socket.io-client:1.0.0') { 
     // excluding org.json which is provided by Android 
     exclude group: 'org.json', module: 'json' 
   }
}