Flutter package http/http.dart target of URI doesn't eixst - flutter

import 'package:http/http.dart' as http;
I encountered this problem!
I added the package to pubspec.yaml file and run flutter pub get (also have tried flutter clean) but when importing in vscode it gives me a notification.
Target of URI doesn't exist: 'package:http/http.dart'. Try creating file reference by URI, or Try using URI for a file that doesn't exist. dart(URI doesn't exist)
How can I solve this problem?

instead of using package:http/http.dart, you can use dio package, by adding dio: ^4.0.0 to pubspec.yaml file. dio only requires a String url.

Ok, now I fixed this problem. I have restarted the IDE but it still doesn't work. So I tried restarting my computer and reopening the terminal with flutter clean and flutter pub get. After that, the error message is gone.

Related

By updating Flutter 3.8.0 Error in flutter_date_time_picker

By updating Flutter 3.8.0
I am getting the following error in flutter_date_time_picker.
I would like to know if anyone knows a solution to this problem.
../../../../.pub-cache/git/flutter_datetime_picker-eb66486c47d50bf550950c196486121ffcea8885/lib/flutter_datetime_picker.dart:7:1: Error:
'DatePickerTheme' is imported from both 'package:flutter/src/material/date_picker_theme.dart' and'package:flutter_datetime_picker/src/datetime_picker_theme.dart'.
pubspeck.yaml
flutter_datetime_picker:
git:
url: https://github.com/Realank/flutter_datetime_picker.git
If anyone knows of a solution, I would love to hear about it.
I believe this is probably due to the flutter update, as I was able to build normally until yesterday!
If anyone knows of a solution, I would love to hear about it.
You can try the following steps:
Remove the flutter_datetime_picker package from your pubspec.yaml file.
Run flutter clean in your terminal to remove any cached files.
Re-install the flutter_datetime_picker package.
first try to flutter clean and then pub get and reinstall the package you want. if again you had this error try this:
To resolve it; in the class where you have both imports, assign an alias to one of the packages using the as keyword.
import 'package:flutter/src/material/date_picker_theme.dart' as dp
dp.EveryMethodYouWant(); //call the class using the alias
if you had any question i'm here.
happy coding.
By mistakenly,you have imported the wrong package because as per the package documentation, there is no such line mentioned.
Import the package mentioned below and try pub get.
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
everything vill works fine.

Flutter assests_audio_player import doesn't work

My flutter has suddenly started giving me this error on assets_audio_player : "Undefined class 'AssetsAudioPlayer'.". The import for the player: import 'package:assets_audio_player/assets_audio_player.dart'; is also greyed out. I've tried upgrading the flutter & restarting the device but the issue is still there. Any clue what might've gone wrong? Thank you!
Before importing the package in your code, did you properly add its dependency in your "pubspec.yaml" file and then run the flutter pub get command?
I am guessing you're using this package.
Be sure to add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get).
dependencies:
assets_audio_player: ^3.0.4+1

Target of URI doesn't exist: 'firebase_options.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist

please how can i solve this problem
Target of URI doesn't exist: 'firebase_options.dart'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exist
I try this flutter clean
flutter pub get
restart
run flutter pub add firebase_core this is probably because you haven't installed firecore in your project yet
Usually, the firebase_options.dart file is generated through flutterfire configure command.
Double check that you generate the file properly with the Flutterfire CLI and that you import it with the right path in your main.dart (or the file that require it)

Target of URI doesn't exist: 'package:image_picker/image_picker.dart'

i tried everything i could to import image_picker and i find on various sites but couldn't get rid of this error :
import 'package:image_picker/image_picker.dart';
Target of URI doesn't exist: 'package:image_picker/image_picker.dart'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exis
already added the dependencies such as :
dependencies:
image_picker: ^0.8.4+8
Running "flutter pub get" it turns out to
OUTPUT:
The plugin flutter_plugin_android_lifecycle doesn't have a main
class defined in C:\Users\Iradukunda
Didier\Documents\flutter_windows_2.8.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-2.0.5\android\src\main\java\io\flutter\plugins\flutter_plugin_android_lifecycle\FlutterAndroidLifecyclePlugin.java
or C:\Users\Iradukunda
Didier\Documents\flutter_windows_2.8.1-stable\flutter.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-2.0.5\android\src\main\kotlin\io\flutter\plugins\flutter_plugin_android_lifecycle\FlutterAndroidLifecyclePlugin.kt.
This is likely to due to an incorrect androidPackage: io.flutter.plugins.flutter_plugin_android_lifecycle or mainClass
entry in the plugin's pubspec.yaml. If you are the author of this
plugin, fix the androidPackage entry or move the main class to any
of locations used above. Otherwise, please contact the author of this
plugin and consider using a different plugin in the meanwhile. exit
code 1
Run flutter packages get instead of flutter pub get. If it does not work, Re-start the Visual Studio Code after flutter packages get
Source:

Undefined name 'Permission' for permission_handler package in flutter

Trying to write a permission code for camera and microphone on flutter
I'm currently using permission_handler: ^5.0.1 and have imported the package after adding the dependency in pubspec.yaml
import 'package:permission_handler/permission_handler.dart';
But when I used the following code,
await Permission.camera.request();
I have the following error.
Undefined name 'Permission'. Try correcting the name to one that is defined, or defining the name.
Any help will be appreciated. Thanks!
I realized later that the error was because I accidentally deleted permission_handler_platform_interface-2.0.2 in my external packages inside the External Libraries > Dart Packages in Flutter SDK.
I resolved it by running
flutter pub cache repair
Try read the docs again. Maybe they have change the code or maybe make sure that you have get the package.