I'm trying to run the example Flutter_blue app, https://github.com/pauldemarco/flutter_blue and I keep getting errors all on the main.dart concerning the FindDevicesScreen and DevicesScreen classes.
I started a new Flutter project, injected flutter blue 0.6.0 dependency, changed the Android app minSdkVersion to 19, copied the main.dart and widgets.dart files from the example https://github.com/pauldemarco/flutter_blue.
The errors I get are:
"The method ScanResultTile isn't defined for the class 'FindDevicesScreen'", "The method ServiceTile, CharacteristicTile and DescriptorTile isn't defined for the class DeviceScreen"
Could anyone recommend a fix or provide a walkthrough of how to successfully run this project?
You're running into this error because you haven't imported the widgets.dart file that's located in the same directory as the main.dart file in the example.
In the example main.dart file, he calls:
import 'package:flutter_blue_example/widgets.dart';
if you replace this with :
import 'widgets.dart';
and save the widgets.dart file into the same directory, it should run.
Related
My flutter project has a separate dart file for each functionality, So, I tried to import a dart file in a new dart file to access the functionality in that file, but I got this error "Target of URI doesn't exist: 'package:filename.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist"
I tried solutions like restarting the Ide, flutter clean command and pub get, Most of the solutions for the same error have to deal with packages, it can be solved by adding package name in dependencies. But this is a dart file, how do I solve it.
When using the import function and going to the root folder with 'package:*', you need to first write the flutter project folder name, and then after that the file or subfolders.
All this but skipping the 'lib' folder.
As an example:
import 'package:flutterProject/subFolderInLib/filename.dart'
Hope this was understandable and worked! :)
In my last flutter project, I included files placed in my lib/ directory by using import 'package:app/file_name.dart'.
For example, my file located at lib/app_controller.dart was imported via:
import 'package:app/app_controller.dart'
I just started a new flutter project, and it is giving me the error:
Error: Could not resolve the package 'app' in 'package:app/app_controller.dart'
When I remove the portion package:app/, it builds fine. I find this very strange because my previous project is still building just fine without any changes. Does anyone know what's happening here?
What is allowing my old project to respect package:app/..., but not my new project?
package:app/ would work only for an application that is called app. What is the name of your new application? When you import items from your own project, it goes like this:
package:{{YOUR APPLICATION NAME}}/{{DIRECTORIES}}
What is the name in your pubspec.yaml file? It's usually on the very first line.
it is because a dart class can be imported in two ways(AFAIK),
local import from the root of current file where import is being used for example import '../folder/file.dart
with a package name which should begin from package for example import package:packagename/any_file_in_the_lib_folder.dart, a package will have a pubspec.yml which defines a package name which will be used to import the content of the lib folder of that package, in your case your first project is named app so it respected this import style but your second project isn't respecting it because its not named app but something else.
I am trying to create a flutter package.
Inside Lib(package) folder, I have MY-PACKAGE.dart file. I also have a folder Called src which contains some codes I will import for use in MY-PACKAGE.dart.
In my pubspec.yaml in Example folder I have added the package like below and run packages get.
onboardly:
path: ../
To use my package I do this
// THERE IS NOT ANY PROBLEM WITH THIS IMPORT STATEMENT
import 'package:onboardly/onboardly.dart';
OnBoardly( // THIS CLASS WORKS FINE
screens: [
OnBoardlyScreenItem( // THIS CLASS CAN NOT BE FOUND EVEN THO IT EXISTS IN THE src FOLDER
image: Image.asset("assets/loadicon.png"),
description: Text("Hello There"),
),
],
),
The problem am facing is the fact that OnBoardlyScreenItem() which is in the src of the package can not be found.
I have ran
flutter packages get
flutter pub get
restarted my IDE
run flutter clean
Adding this for anyone later,
I had to export those classes or files that I wanted to be available to the Package to the "Entry file" since the folders in my case are regarded as private. Export all files or classes you'll want to be available to the user.
// Exporting all codes to be avaible to package
export 'package:onboardly/src/IntroScreen/OnBoardlyScreenItem.dart';
I'm trying to make a flutter version of my old app , it needs NFC .
First I create a default project for test run and it works fine.
I tried to use flutter-nfc-reader and install it following "Installation" in that default project.
And here comes the problem:
After I edit "pubspec.yaml" and do "packeges get" , it automatically edit "GeneratedPluginRegistrant" under "myapp/android/app/src/main/java/io.flutter.plugins".
added
import it.matteocrippa.flutternfcreader.FlutterNfcReaderPlugin;
and
FlutterNfcReaderPlugin.registerWith(registry.registrarFor("it.matteocrippa.flutternfcreader.FlutterNfcReaderPlugin"));
But the import can't find that package "it.matteocrippa.flutternfcreader" which is inside the plugin.
I tried just copy that package but that file will be full of error when it is inside my project.
I have no idea how to fix it....
As Github reads:
last step import to the project:
import 'package:flutter_nfc_reader/flutter_nfc_reader.dart';
I have stumbled upon a problem in importing the package in Flutter, I tried to solve this by running flutter packages get and also shutting down the project in Android studio and reopening it.
import 'package:task_02_category_widget/category.dart';
Here is the line above, and the error I'm running into when I run it gives the following error in the console.
Your application could not be compiled, because its dependencies could
not be established.
The following Dart file:
/Users/username/Documents/flutter_rectangle_2/lib/main.dart
...refers, in an import, to the following library:
package:task_02_category_widget/category.dart
That library is in a package that is not known. Maybe you forgot to
mention it in your pubspec.yaml file?
If task_02_category_widget/category.dart is part of an old project you are reusing you should put it in a folder in your flutter application and include it like "../ folder /task_02_category_widget/category.dart ". If it is part of github repository you have copy pasted from, just copy the file and use the step above. Most probably you are looking for that . In any other case check here to find the source code.
You should have in your project at a file called pubspec.yaml a definition like this:
name: my_app
dependencies:
task_02_category_widget:
Let’s say that your package is laid out as follows:
task_02_category_widget/
lib/
category.dart
Then, you can import it:
import 'package:task_02_category_widget/category.dart';
More information:
https://www.dartlang.org/tools/pub/get-started
https://www.dartlang.org/guides/libraries/create-library-packages