Flutter assests_audio_player import doesn't work - flutter

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

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.

Why is flutter not detecting locally made packages?

I have been assisting with building an app with Flutter.
My senior shared the repo with me, however when I cloned it, all of the import packages had a 'uri not found' error.
I ran flutter pub get, and all of the external packages work. However the locally made packages, such as 'package:projectname/utils/utils.dart' still have an error.
How can I fix this? Preferably the fix is in my enviroment. I do not want to change any of the code since it works for him. TIA.
pubspec.yaml
dependencies:
flutter:
sdk: flutter
stackoverflow_pkg:
path: C:\Users\xxxxx\flutter_projects\stackoverflow\stackoverflow_pkg
code:
import 'package:stackoverflow_pkg/stackoverflow_pkg.dart';

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

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.

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.

Can't import font awesome flutter?

Im new to Flutter, i use Visual Studio Code with Flutter extension. I try to import the package "font awesome" but i got an error. I search on internet but nothing solve that.
Error
pubspec.yaml
Flutter pub get
Import package
If still not importing then restart IDE
hope this will work
If you run flutter pub add font_awesome_flutter or flutter pub get font_awesome_flutter and the import statement still shows an error, try running flutter pub upgrade font_awesome_flutter.