[ERROR: Unable to load asset: assets/audios/note1.wav in flutter - flutter

I have this question. My code actually working but when I click my button there is no new sound. I actually change the name of directory folder but it didn't work.
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'dart:math';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
void playSound () {
final player = AudioPlayer();
int soundNumber = Random().nextInt(5) + 1;
player.setSource(AssetSource('sounds/note$soundNumber.wav'));
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child:TextButton
(onPressed: () {
playSound();
},
child:const Text('Click Me')),
),
),
),
);
}
}
Here is the result:
E/flutter ( 8119): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)]
Unhandled Exception: Unable to load asset: assets/audios/note1.wav
E/flutter ( 8119): #0 PlatformAssetBundle.load
(package:flutter/src/services/asset_bundle.dart:237:7)
E/flutter ( 8119): <asynchronous suspension>
yaml file :
assets:
- assets/sounds/

You have to add this file in assets section in pubspec.yaml file
assets:
- assets/audios/note1.wav

try to move your sub audio folder out of your former asset folder that comes by default . and place it direct to your project new folder like lib folder in the first level
sometimes flutter does not see the external files .
and for better work done clean your engine .

As I'm working in the Xylophone project
I did this to run my APP:
You can add new project and then rewrite your code line by line and debug it
probably it is because of some change that you have done.
Change the package I recommend you to add the new package in new projects
PS: If you are in windows before everything quit the Android Studio from the Task Manager and shut down your computer then start everything from the beginning
If you find new solution let me know
Thank you

Related

Flutter firebase auth for desktop

I'm trying to create an app that performs a Firebase authorization on a desktop.
I didn't find any full sample code for this so I started by create a basic demo project on VScode.
As soon as I add the package flutter pub add firebase_auth_desktop (without adding code to the app), I get errors when I try to run the app.
/C:/Users/yvan_/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core-1.24.0/lib/src/firebase_app.dart(18,25): error G75B77105: Member not found: 'FirebaseAppPlatform.verifyExtends'.
[C:\FDSTiming\Project\Flutter\app3\build\windows\flutter\flutter_assemble.vcxproj]
/C:/Users/yvan_/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_auth_platform_interface-6.10.1/lib/src/action_code_info.dart(65,15): error GE5CFE876: The method 'FallThroughError' isn't defined for the class 'ActionCodeInfo'. [C:\FDSTiming\Project\Flutter\app3\build\windows\flutter\flutter_assemble.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(247,5): error MSB8066: Custom build for 'C:\FDSTiming\Project\Flutter\app3\build\windows\CMakeFiles\18de2b4c67371752531dc30d7008f913\flutter_windows.dll.rule;C:\FDSTiming\Project\Flutter\app3\build\windows\CMakeFiles\122a37675ed5a5d637290377de62a3e1\flutter_assemble.rule;C:\FDSTiming\Project\Flutter\app3\windows\flutter\CMakeLists.txt' exited with code 1. [C:\FDSTiming\Project\Flutter\app3\build\windows\flutter\flutter_assemble.vcxproj]
Exception: Build process failed.
The code is:
import 'package:flutter/material.dart';
//import 'package:firebase_auth_desktop/firebase_auth_desktop.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
#override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello World!'),
),
),
);
}
}
And pubspec.yaml:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
firebase_auth_desktop: ^1.0.2
Any idea?
I managed to get rid of the first error by adding:
firebase_core_platform_interface: 4.5.1
firebase_messaging: ^13.0.4
But didn't find any clues for the others errors
The flutter firebase_core dependency currently not supported by windows platform.

Update new version is not working in flutter

I have a flutter app which has an update button. This is used to update when new version is available in play store. It works fine until few days before. But now it is not working. It only shows a notification when user has installed the same version otherwise an error will be thrown.
> 2022-07-04 12:01:39.072 27969-28023/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: No element
#0 ListMixin.firstWhere (dart:collection/list.dart:167)
#1 NewVersion._getAndroidStoreVersion (package:new_version/new_version.dart:157)
<asynchronous suspension>
#2 _SettingsPageState._checkVersion (package:bnews/ui_components/pages/settings_page.dart:196)
<asynchronous suspension>
So now I cant update my app using this update button. I use new_version flutter package to update. This is the code
void _checkVersion() async {
final newVersion = NewVersion(
androidId: "com.abc.def",
);
final status = await newVersion.getVersionStatus();
newVersion.showUpdateDialog(
context: context,
versionStatus: status!,
dialogTitle: "UPDATE!!!",
dialogText: "Please update the app from " + "${status.localVersion}" + " to " + "${status.storeVersion}",
updateButtonText: "Lets update",
);
}
I think package not found problem is there. But it works fine until few days before. I have also updated new_version package but still same problem. Is this problem with playstore?
this is a bug check pub.dev new_version issues
for checking if there is a new version, I use upgrader package, just wrap the home of your materialApp and it will handle everything:
home: UpgradeAlert(
upgrader: Upgrader(
showReleaseNotes: false,
dialogStyle: UpgradeDialogStyle.cupertino,
shouldPopScope: () => true,
),
child: MyHomepage(),
),
Anyone who still face this issue can try a new package new_version_plus,you can use the same code by just changing name,its that simple

Loading image in Flutter | Path from content root doesn't work, but absolute path works

Very simple app, the image is in project/images folder.
When I try to load it from the relative path:
'images/diamond.png'
the image doesn't load.
When I do it from the absolute path: '/Users/MacBookAir/StudioProjects/secondtry_iamrich/images/diamond.png'
it does.
Why is this? Can anyone please help?
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: const Text('I am Rich'),
backgroundColor: Colors.blueGrey[900],
),
body: const Center(
child: Image(
image: AssetImage('images/diamond.png'),
),
),
),
),
);
}
This is the error it is providing:
======= Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: images/diamond.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:658:14)
<asynchronous suspension>
Image provider: AssetImage(bundle: null, name: "images/diamond.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#99cb5(), name: "images/diamond.png", scale: 1.0)
====================================================================================================
Do not forgot to add image folder path to your pubspec.ymal folder like
assets:
- assets/images/
- assets/images/icons/
- assets/loader.json
Use this plugin in your android studio it will auto generate your all assets no need to write path.
Use it like this
Image.asset(Assets.imagesNoDataFound, scale: 3.5)
Uncomment and change the asset section in your pubspect.yaml file can fix it.
assets:
- images/

Flutter : firebase MissingPluginException

I'm having this problem about flutter and firebase(realtime-database).
Unhandled Exception: MissingPluginException(No implementation found for method Query#observe on channel plugins.flutter.io/firebase_database)
Here is the error in terminal
error
// error message
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method Query#observe on channel plugins.flutter.io/firebase_database)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
<asynchronous suspension>
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#2 Query._observe.<anonymous closure> (package:firebase_database/src/query.dart:50:38)
#3 _runGuarded (dart:async/stream_controller.dart:820:24)
#4 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:215:7)
#5 _ControllerStream._createSubscription (dart:async/stream_controller.dart:833:19)
#6 _StreamImpl.listen (dart:async/stream_impl.dart:475:9)
#7 Stream.first (dart:async/stream.dart:1254:25)
#8 Query.once (package:firebase_database/src/query.dart:84:55)
#9 _IoTState.initState (package:flutter_try_iot/main.dart:36:13)
#10 StatefulElement._f<…>
I'm trying to get data from firebase to display in flutter app.
Here is my code main.dart
class _IoTState extends State<IoT> {
final getIot = FirebaseDatabase.instance.reference();
final getData = FirebaseDatabase.instance.reference().child('xxx-xxx');
String temperatue = "0";
String illuminance = "0";
List<String> temp = [];
List<String> light = [];
#override
void initState(){
getData.once().then((DataSnapshot snapshot){
if (snapshot.value == null) {
print("Item doesn't exist in the db");
} else {
print("Item exists in the db");
}
});
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF7ACADA),
title: Text(
"IoT ZigBee Simulation",
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF1A1244)
),
),
),
body: Column(
),
);
}
}
pubspec.yaml
firebase_core: ^0.4.5
firebase_database: ^3.1.6
flutter_icons: ^1.1.0
fl_chart: ^0.10.1
I follow instructions to add ios to firebase .ios add firebase
no issues found by flutter doctor
I follow other peoples suggestion to do flutter clean & flutter packages get, but still not able to fix this problem
https://github.com/flutter/flutter/issues/13971
terminal
Also pop up a window telling me The file “Runner.xcworkspace” has been modified by another application" everytime I execute flutter clean/ flutter packages get
I successfully connect to firebase yesterday, but after I close my simulator I start to receive error message
success picture
Please give me some solution or advice to fix this problem, thanks.
Please tell me if I need to provide additional information

how to run firstapp flutter 1.5

i tryed testdrive for flutter installed on windows as here https://flutter.dev/docs/get-started/test-drive
defaut application generated work, well, but when i try to follow the snd part at
https://flutter.dev/docs/get-started/codelab
i get errors:
error: The function 'MyApp' isn't defined. (undefined_function at [flutter_app007] lib\main.dart:3)
error: 'MaterialApp' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:8)
error: 'Scaffold' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:10)
error: 'AppBar' isn't a function. (invocation_of_non_function at [flutter_app007] lib\main.dart:11)
for this code in main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: const Text('Hello World'),
),
),
);
}
}
i checked flutter doctor, but show nothing bad.. any idea?
go to the project directory and open windows cmd. and try flutter run
ok, i finally resolved the problem.
when i was typed 'flutter_console.bat', i was get after, 'mysql is unknow program '. i finally founded that an install of MySQL Fabric 1.5 & MySQL Utilities 1.5\ setted his path in PATH env variable. this path poisonned result path integration , returning 'mysql is unknow program' and stopping project generation.. . desinstalling the mysql software solved the problem by cleaning path from his entry and now, the project can be created and work as expected..
very strange, no..?