How to use SQlite database using sqflite package in my Flutter App - flutter

I'm a beginner in flutter, I want to use SQLite database using sqflite package in my Flutter App,
when I use import 'package:path_provider/path_provider.dart';I have a compilation error saying Target of URI doesn't exist: 'package:path_provider/path_provider.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.
and when I use
io.Directory documentDirectory = await getApplicationDocumentsDirectory();
I have a compilation error saying
Try correcting the name to the name of an existing method, or defining a method named 'getApplicationDocumentsDirectory'.```

Looks like you need to add path_provider dependency to your pubspec.yaml.
Add this:
dependencies:
...
path_provider: ^2.0.11
Then run
flutter pub get
More info: https://pub.dev/packages/path_provider

Related

Not a valid Dart package name - Flutter error

I want my app to be available for the web.
I run this command: flutter create .
I get this error: "Fredi" is not a valid Dart package name.
I know that there shouldn't be any capital letters. However, I do not know how to change the dart package name.
I have already used these packages successfully, but they seem to be changing other things, not the Dart Package Name.
change_app_package_name: ^1.1.0
rename: ^2.0.1
The only thing in my project with the name 'Fredi' is the root folder (original project name). However, I don't know how to change it (file explorer won't let me) and it will probably break things.
What step can I take?
Config Files
app/build.gradle -> applicationId "com.tomasward.fredi"
android manifest -> package="com.tomasward.fredi"
android manifest -> android:label="Fredi"> [I understand this is the name displayed to the user, I've tried changing it but it doesn't fix the error.]
You can run flutter create --project-name "your_valid_package_name" InvalidPackageNameDirectory to create a Flutter project in a directory with a non-valid package name.
In an already existing project, you can change the package name by modifying the name property in the pubspec.yaml at the root of the project (see here for more details on the pubspec).
You can probably rename your package name with the help of some dependency that you can find on pub.dev by typing "rename" in the search bar.
All those dependencies will help you rename your package to a lowercase only package name, then you will be able to use the flutter create . command to create the web folder for your app.

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

Flutter - Asset images in package dependencies

We have the following structure:
Package A is a flutter app, It has it's assets folder and is loading assets like this: Image.asset("assets/images/background.png"). project B, that uses package A as dependency.
When I run package A from Project B, some widget of package A have image can not show. Error: Another exception was thrown: Unable to load asset: assets/images/light_theme_background.svg
When I added the "package" field to the AssetImage in the package A, Error is fixed when I run package A from project B, however the package A couldn't read its own contents.
const AssetImage('assets/heart.png', package: 'my_packages');
Is there a way to package A when it can read assets on run from itself and run from the project that takes it as a dependency?
Error when run package A: "Another exception was thrown: Unable to load assets: package/my_packages/assets/images/background.png"
In the documentation it says: "Content used by the package itself should also be fetched using the package argument as above."
I tried copying assets folder to lib folder and also declaring in pubspec.yaml file like the answer here. However, most reported "Bad state: Invalid SVG data " and "Exception: Invalid image data" errors even though they are all normal.

Flutter getx package - Error: No named parameter with the name 'findProxy'

When I run the project I get an error like this, flutter clean and then flutter pub get tried but no result. Thanks for read, please help..
==>
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.0/lib/get_connect/http/src/http.dart:60:11: Error: No named parameter with the name 'findProxy'.
findProxy: findProxy,
^^^^^^^^^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.0/lib/get_connect/http/src/http/html/http_request_html.dart:13:3: Context: Found this candidate, but the arguments don't match.
HttpRequestImpl({
^^^^^^^^^^^^^^^
Most probably, this is caused because the package is not compatible with the current version of flutter or vice versa.
Try updating the package version from:
https://pub.dev/packages/http
Also, try importing the package using following command:
import 'package:http/http.dart' as http;
and then use functions as follows:
http.post()

The method 'getApplicationDocumentsDirectory' isn't defined for the type '_MyAppState'

so a part of my code is
Future<void> _loadModel() async {
final bytes =
await rootBundle.load('assets/deepspeech-0.9.3-models.tflite');
final directory = (await getApplicationDocumentsDirectory()).path;
And i keep getting the error:
The method 'getApplicationDocumentsDirectory' isn't defined for the type '_MyAppState'.
Try correcting the name to the name of an existing method, or defining a method named 'getApplicationDocumentsDirectory'
What should i do? help me please!
You have to install path provider package by running flutter pub add path_provider in your terminal. If you already installed it. check whether you are importing it to your file.
Import this...
import 'package:path_provider/path_provider.dart';
Add path_provider: ^2.0.11 to pubspec.yaml file.
Run Pub Get.
And Import this
import 'package:path_provider/path_provider.dart';