Flutter How to import backendless_sdk messaging module? - flutter

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?

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:

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.

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'
}
}

Related

How to check internet connectivity in Flutter?

import 'package:internet_connection_checker/internet_connection_checker.dart';
/*Error --> Target of URI doesn't exist: 'package:internet_connection_checker/internet_connection_checker.dart'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exist*/
....
void checkingNetwork() async {
ans = await InternetConnectionChecker().hasConnection;
/*Error -- The method 'InternetConnectionChecker' isn't defined for the type '_WelcomeMessageState'.
Try correcting the name to the name of an existing method, or defining a method named 'InternetConnectionChecker'.*/
}
#override
void initState() {
super.initState();
checkingNetwork();
}
I have this code to check network connectivity but even after adding plugin to pubspec, its giving error. How can I remove this?
If you want to use a package called internet_connection_checker, you have to add it to your pubspec.yaml file.
Then you can run flutter pub get to install the package.
If you have done that, the import line
import 'package:internet_connection_checker/internet_connection_checker.dart';
should compile successfully and the symbol InternetConnectionChecker will be found.
After adding The Package In pubspec.yaml Please Do flutter clean && flutter pub get command to get the packages , Or You Can Use connectivity_plus package . This has listener in it So you Can Track The Internet Connectivity Through The App AllTime

Undefined name 'Provider' in flutter

I am getting an error called "Undefined name 'Provider' in flutter. Here is the code snippet for it:
addData() async {
UserProvider _userProvider = Provider.of(context, listen : false);
await _userProvider.refreshUser();}
Can someone help me figure this out?
You need to import the provider package on the current page
import 'package:provider/provider.dart';
Provider is a powerful State Management package which has to be added to the project and imported in order to use it.
If you haven't added the package, then add it by the following command in the project folder in Terminal/Command Prompt:
flutter pub add provider
Then in the file containing the snippet, import the package at the top like the following:
import 'package:provider/provider.dart';
Check if you have following dependency added in your pubspec.yaml file
dependencies:
provider: ^6.0.3
If not add it or simply run in your terminal
flutter pub add provider
After getting your dependency import the provider package in your page:
import 'package:provider/provider.dart';

How to suppress depend_on_referenced_packages just for a specific import, not the whole file?

After upgrading to Flutter 3.0 I started to get a lot of depend_on_referenced_packages lint issues when running flutter analyze. If I remove the reported imports the compilation breaks. Most of the issues are with package:collection/collection.dart which provides extension methods.
Currently the best I could find is to suppress this lint for the affected files by adding // ignore_for_file: depend_on_referenced_packages. However I like this lint (and in general I'd want to keep as much lints enabled as possible), so is there a way to suppress the lint only for a just a specific import and not for all imports in the file?
Relevant sections of pubspec.yaml:
...
environment:
sdk: ">=2.17.1 <3.0.0"
flutter: ">=3.0.1"
...
dev_dependencies:
flutter_lints: ^2.0.1
Running:
$ flutter analyze
...
info • Depend on referenced packages • lib/preferences/palette_spec.dart:3:8 • depend_on_referenced_packages
info • Depend on referenced packages • lib/ui/parts/circular_menu.dart:5:8 • depend_on_referenced_packages
...
Source code examples:
database_utils.dart (firstWhereOrNull is from collection.dart):
...
import 'package:collection/collection.dart';
...
Activity? _getActivityById(int id) {
return activities.firstWhereOrNull((element) => element.id == id);
}
...
Record? _getRecordById(int id) {
return records.firstWhereOrNull((element) => element.id == id);
}
palette_spec.dart (forEachIndexed is from collection.dart):
...
import 'package:collection/collection.dart';
...
paletteStr.split(",").forEachIndexed((index, colorStr) {
...
});
circular_menu.dart:
...
import 'package:vector_math/vector_math.dart' as vector;
...
final angle = vector.radians(90.0 / (widget.children.length - 1) * index + angleFix);
Note: the root cause is that collection is brought in as a transitive dependency.
Originally I misunderstood the lint. Explanation to Petr's solution: when he says "lint is reported if you depend on a transitive dependency" it means that somewhere in my code I have an import which imports stuff from that dependency. But at the time of the lint that dependency is only transitive, not direct. Therefore if I'd decide - for whatever reason - to not depend on the package which brings that in then suddenly I'd have an error out o the blue for that import. The lint tries to make that dependency graph more direct.
This lint is reported if you depend on a transitive dependency. Do you have in your pubspec.yaml defined collection?
dependencies:
collection: ^1.16.0
I had same issue but after defining dependency, lint issue is gone.

Flutter, AmplifyStorageS3 plugin not added correctly

getting
Error :
/*
dynamic AmplifyStorageS3()
package:my_budget_app/main.dart
AmplifyStorageS3 isn't a type.
Try correcting the name to match an existing type
*/
I am following this docs
https://docs.amplify.aws/lib/storage/getting-started/q/platform/flutter/#provision-backend-storage
Amplify storage S3 is not imported correctly.
I cleared cache and reinstalled all the pubs
I deleted publock file and pub get all the files no luck
I restarted vscode a couple of times no luck
I see the import says not used so AmplifyStorageS3 class is not exported from the package
ackage:amplify_storage_s3/amplify_storage_s3.dart ???
I have 3 ideas.
1: In package import import 'package:amplify_storage_s3/amplify_storage_s3.dart'; add "as ampl" to the end and then you will have something like this:
import 'package:amplify_storage_s3/amplify_storage_s3.dart' as ampl;
And then write:
ampl.AmplifyStorageS3 storage = ampl.AmplifyStorageS3();
2: Hold ctrl and left click on the imported package, find this class in the package and find out what's wrong.
3: Check your pubspec.yaml and so on for minimum requirements:
environment:
sdk: ">=2.12.0 <3.0.0"

Can't run Flutter web on Chrome Device with BluetoothThermalPrinter package

Can't run my flutter web app when blue_thermal_printer package is being used.
Compiler show these errors:
import 'package:blue_thermal_printer/';
^
/D:/All%20Data/Softwares/Latest%20Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/blue_thermal_printer-1.1.8/lib/blue_thermal_printer.dart:189:23:
Error: Type 'Registrar' not found.
static registerWith(Registrar value){
^^^^^^^^^
lib/generated_plugin_registrant.dart:31:3: Error: Getter not found: 'BlueThermalPrinterPlugin'.
BlueThermalPrinterPlugin.registerWith(registrar);
What I have tried until now:
1- Tried to enable flutter web support with this command: flutter create .
2- Tried to create a new class BlueThermalPrinterPlugin in the package file blue_thermal_printer.dart with the following method:
class BlueThermalPrinterPlugin{
static var nameoo ;
static registerWith(Registrar value){
this.nameoo=value;
return nameoo;
}
}
But that doesn't either helps because sdk generated automatic generated_plugin_registrant.dart which produces incomplete import i.e import 'package:blue_thermal_printer/'; causing compile time issue.
I need to run my flutter app on web which was working fine a few days before.
Thanks to the developer of this package whom I contacted personally and he corrected the error in packge. blue_thermal_printer 1.2.0 is working fine and doesn't contain this error anymore.