Flutter not load assets - flutter

I have a problem with flutter the assets below are not displayed inside the widget, it tells me unable to load assetss how can I do to fix this?
Dart Code:
final cookingEvent = Event(
imagePath: "assets/event_images/granite_cooking_class.jpeg",
title: "Basket",
description: "",
location: "Ferrara(FE)",
duration: "1ms",
punchLine1: "Partecipa!",
punchLine2: "nuova partita di calcio",categoryIds: [0, 2],
galleryImages: ["assets/event_images/cooking_1.jpeg", "assets/event_images/cooking_2.jpeg", "assets/event_images/cooking_3.jpeg"]);
Flutter Exception:
r: "assets/event_images/5_km_downtown_run.jpeg", scale: 1.0)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: Unable to load asset: assets/event_images/granite_cooking_class.jpeg
flutter: Another exception was thrown: Unable to load asset: assets/event_images/music_concert.jpeg
flutter: Another exception was thrown: Unable to load asset: assets/event_images/golf_competition.jpeg
Pubspec.yaml:
assets:
- assets/guest_images/
- assets/event_images/
- assets/fonts/
fonts:
- family: Montserrat
fonts:
weight: 700

Make sure that the path of your image is correct.
Then check for tab spaces.
make sure to run flutter pub get command.
Then restart your app or hot reload your app.

Related

Flutter audioplayers: ^2.0.0 error Unhandled Exception: Unable to load asset: assets//data/user/0/com.xxxx.xxxx/cache/flip.mp3

I'm trying to use audioplayers: ^2.0.0,but i got this error, how to solve it?please!
pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/audio/
Code
Future setAudio() async {
AudioPlayer audioPlayer = AudioPlayer();
audioPlayer.setReleaseMode(ReleaseMode.loop);
AudioCache audioCache = AudioCache(prefix: 'assets/audio/');
final url = await audioCache.load('flip.mp3');
audioPlayer.setSourceAsset(url.path);
}
You shouldn't use the full path in setSourceAsset, and since you've already set a prefix for the cache you kust have to write the filename:
audioPlayer.setSourceAsset('flip.mp3');

The Flutter build is stuck on the splash screen

Flutter build is stuck on the splash screen. I tried it on both a real device and the Pixel 4 Api33 emulator. Using Namal woocommerce source code available on codecanyon website and I am a beginner. I tried my best to figure out what's wrong but I failed. Asking for your help guys, please let me know if you need any other information.
**main.dart error log file on Pixel 4 Api33 emulator**
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
D/FlutterGeolocator(10640): Attaching Geolocator to activity
W/FlutterActivityAndFragmentDelegate(10640): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
D/FlutterGeolocator(10640): Creating service.
D/FlutterGeolocator(10640): Binding to location service.
D/FlutterLocationService(10640): Creating service.
D/FlutterLocationService(10640): Binding to location service.
D/FlutterGeolocator(10640): Geolocator foreground service connected
D/FlutterGeolocator(10640): Initializing Geolocator services
D/FlutterGeolocator(10640): Flutter engine connected. Connected engine count 1
Debug service listening on ws://127.0.0.1:54544/-pXfnrJ83sQ=/ws
Syncing files to device sdk gphone64 x86 64...
V/OneSignal(10640): Initializing the OneSignal Flutter SDK (3.3.2)
D/OneSignal(10640): Adding a task to the pending queue with ID: 1
D/OneSignal(10640): startPendingTasks with task queue quantity: 1
D/OneSignal(10640): Attempted to clean 6 month old IAM data, but none exists!
D/OneSignal(10640): OneSignal InAppMessageTracker initInfluencedTypeFromCache: OSChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}
D/OneSignal(10640): OneSignal NotificationTracker initInfluencedTypeFromCache: OSChannelTracker{tag=notification_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}
D/OneSignal(10640): OneSignal getUnattributedUniqueOutcomeEventsSentByChannel: null
W/OneSignal(10640): appContext set, but please call setAppId(appId) with a valid appId to complete OneSignal init!
V/OneSignal(10640): setAppId called with id: YOUR_ONESIGNAL_APP_ID changing id from: null
V/OneSignal(10640): Starting OneSignal initialization!
D/OneSignal(10640): Retrieved IAMs from DB redisplayedInAppMessages: []
V/OneSignal(10640): No class found, not setting up OSRemoteNotificationReceivedHandler
I/OneSignal(10640): Last Pending Task has ran, shutting down
V/OneSignal(10640): OneSignal SDK initialization delayed, waiting for remote params.
D/OneSignal(10640): Starting request to get Android parameters.
D/OneSignal(10640): OneSignalRestClient: Making request to: https://api.onesignal.com/apps/YOUR_ONESIGNAL_APP_ID/android_params.js
W/SQLiteLog(10640): (28) double-quoted string literal: "notification"
D/OneSignal(10640): OneSignalRestClient: Adding header if-none-match: W/"05702b137a259242f45cdd80824abb9f"
D/TrafficStats(10640): tagSocket(135) with statsTag=0x2710, statsUid=-1
V/OneSignal(10640): OneSignalRestClient: After con.getResponseCode to: https://api.onesignal.com/apps/YOUR_ONESIGNAL_APP_ID/android_params.js
D/OneSignal(10640): OneSignalRestClient: GET - Using Cached response due to 304: {"awl_list":{},"receive_receipts_enable":false}
D/OneSignal(10640): OneSignal saveInfluenceParams: InfluenceParams{indirectNotificationAttributionWindow=1440, notificationLimit=10, indirectIAMAttributionWindow=1440, iamLimit=10, directEnabled=false, indirectEnabled=false, unattributedEnabled=false}
D/OneSignal(10640): reassignDelayedInitParams with appContext: androidx.multidex.MultiDexApplication#7610e7d
V/OneSignal(10640): setAppId called with id: YOUR_ONESIGNAL_APP_ID changing id from: null
V/OneSignal(10640): Starting OneSignal initialization!
V/OneSignal(10640): No class found, not setting up OSRemoteNotificationReceivedHandler
E/OneSignal(10640): OneSignal AppId format is invalid.
E/OneSignal(10640): Example: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'
E/OneSignal(10640):
E/OneSignal(10640): java.lang.IllegalArgumentException: Invalid UUID string: YOUR_ONESIGNAL_APP_ID
E/OneSignal(10640): at java.util.UUID.fromString(UUID.java:194)
E/OneSignal(10640): at com.onesignal.OSUtils.initializationChecker(OSUtils.java:118)
E/OneSignal(10640): at com.onesignal.OneSignal.init(OneSignal.java:841)
E/OneSignal(10640): at com.onesignal.OneSignal.setAppId(OneSignal.java:735)
E/OneSignal(10640): at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1181)
E/OneSignal(10640): at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:889)
E/OneSignal(10640): at com.onesignal.OneSignal$7.complete(OneSignal.java:1122)
E/OneSignal(10640): at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:211)
E/OneSignal(10640): at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
E/OneSignal(10640): at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:156)
E/OneSignal(10640): at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:279)
E/OneSignal(10640): at java.lang.Thread.run(Thread.java:1012)
V/OneSignal(10640): initWithContext called with: androidx.multidex.MultiDexApplication#7610e7d
V/OneSignal(10640): Starting OneSignal initialization!
V/OneSignal(10640): No class found, not setting up OSRemoteNotificationReceivedHandler
I/flutter (10640): --> GET https://sidemenclothing.in/wp-json/api/tc_settings/app_all_settings
I/flutter (10640): {clientid: 1234, clientsecret: sk_1234, X-Requested-With: XMLHttpRequest, authorization: }
[log]
<-- START PARAMS:
null
END PARAMS -->
<-- END HTTP
I/flutter (10640): Hivedata
I/flutter (10640): Instance of 'BoxImpl<WooCartData>'
E/flutter (10640): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
E/flutter (10640): #0 List.[] (dart:core-patch/growable_array.dart:264:36)
E/flutter (10640): #1 _SplashScreenState.getCart (package:flutter_kundol/ui/screens/splash_screen.dart:136:28)
E/flutter (10640): <asynchronous suspension>
E/flutter (10640):
I/flutter (10640): <-- 200 GET https://sidemenclothing.in/wp-json/api/tc_settings/app_all_settings
[log]
<-- START RESPONSE:
{last_tab: 1, home_style: 1, category_style: 1, banner_style: 3, card_style: 1, cancel_order_button: 0, cancel_order_hours: 1, package_name: app.beastdeals, site_url: https://sidemenclothing.in/, new_product_duration: 5, filter_max_price: 100000, update_order: 10, one_page_checkout: 1, checkout_process: yes, custom_css_for_checkout: .site-header, nav, #secondary, footer {display: none!important;}, contact_us_email: info#domain-name.com, from_email: from#domain-name.com, phone_no: +92 123 456-789, address: 228 Park avs, city: New York, state: NY, Zip: 10003, Country: USA, Latitude: 40.730610, Longitude: -73.935242, sidebar_menu_icon: 0, wish_list_page: 0, edit_profile_page: 0, shipping_address_page: 0, my_orders_page: 0, contact_us_page: 0, about_us_page: 0, bill_ship_info: 0, downloads: 0, news_page: 0, intro_page: 0, share_app: 0, rate_app: 0, setting_page: 0, notification_title: Theme Coder, notification_text: A bundle of products wating for you!, notification_duration: 0, facebook_login: 0, about_page_id: , refund_page_id: , privacy_page_id: , terms_page_id: , wpml_enabled: 0, mvf_enabled: 0, wp_point_reward: 0, wp_multi_currency: 0, delivery_tracking: 0, tracking_url: http://urltracking.com/, geo_fencing: 0, one_signal_notification: 0, one_signal_app_id: , one_signal_app_key: , privacy_page: , refund_page: , terms_page: , about_page: , currency: {name: INR, position: left}, language: {name: en_US}}
END RESPONSE -->
<-- END HTTP
E/flutter (10640): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter (10640): #0 _SplashScreenState.build.<anonymous closure> (package:flutter_kundol/ui/screens/splash_screen.dart:74:76)
E/flutter (10640): #1 _BlocListenerBaseState._subscribe.<anonymous closure> (package:flutter_bloc/src/bloc_listener.dart:204:24)
E/flutter (10640): #2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1586:10)
E/flutter (10640): #3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (10640): #4 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (10640): #5 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (10640): #6 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (10640): #7 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (10640): #8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (10640):
D/EGL_emulation(10640): app_time_stats: avg=988.05ms min=162.14ms max=1813.96ms count=2
**pubsec.yml file**
name: flutter_kundol
description: A new Flutter ecommerce application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: '>=2.17.6 <3.0.5'
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
flutter_bloc: ^7.3.3 # need to change InitialState implementations for above 7.3.3
equatable: ^2.0.5
shared_preferences: ^2.0.15
carousel_slider: ^4.1.1
dio: ^4.0.6
cached_network_image: ^3.2.1
flutter_html: ^2.2.1
# flutter_range_slider: "^1.5.0"
firebase_auth: ^4.1.1
google_sign_in: ^5.4.1
firebase_core: ^2.1.1
flutter_login_facebook: ^1.6.0
share: ^2.0.4
in_app_review: ^2.0.4
onesignal_flutter: ^3.4.1
flutter_svg: ^0.23.0+1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.5
launch_review: ^3.0.1
dropdown_search: ^1.0.0
google_maps_place_picker_mb: ^2.0.0-mb.22
google_maps_flutter: ^2.1.12
bubble_tab_indicator: ^0.1.6
webview_flutter: ^2.8.0
url_launcher: ^6.1.5
hive: ^2.2.3
path_provider: ^2.0.11
hive_flutter: ^1.1.0
dev_dependencies:
hive_generator: ^1.1.3
build_runner: ^2.2.0
change_app_package_name: ^1.1.0
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/langs/
- assets/images/
- assets/icons/
- assets/json/
fonts:
- family: MontserratRegular
fonts:
- asset: assets/fonts/Montserrat-Regular.ttf
- family: MontserratLight
fonts:
- asset: assets/fonts/Montserrat-Light.ttf
- family: MontserratMedium
fonts:
- asset: assets/fonts/Montserrat-Medium.ttf
- family: MontserratBold
fonts:
- asset: assets/fonts/Montserrat-Bold.ttf
- family: MontserratSemiBold
fonts:
- asset: assets/fonts/Montserrat-SemiBold.ttf
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

FlutterError (Unable to load asset: assets/chat1 .txt)

I know I placed my text file at the location assets\chat1.txt, and my code also works with other txts but somehow I always get the following error:
Exception has occurred.
FlutterError (Unable to load asset: assets/chat1.txt)
my Code:
Future<String> getFileData(String path) async {
return await rootBundle.loadString(path);
}
pubspec.yaml
flutter:
assets:
- assets/
Add the full path in pubspec.yaml file and you should consider the indentation for assets:
flutter:
assets:
- assets/chat1.txt

Flutter 1.0 - Unable to load text asset

I'm having some trouble loading text assets in flutter (1.0).
This is the current code attempting to read the asset.
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<String> getFileData(String path) async {
return await rootBundle.loadString(path);
}
Future<File> get _localFile async {
final path = await _localPath;
final file = File('$path/toon_test_3.json');
bool exists = file.existsSync();
if(exists){
return file;
} else {
// Load the default file
final newfile = await getFileData('toonRepo/data.json');
return file.writeAsString(newfile);
}
}
loadString will failing popping up the following:
Could not load source 'dart:core/runtime/libobject_patch.dart': <source not available>.
If execution continues the following exception is raised:
Exception has occurred.
FlutterError (Unable to load asset: toonRepo/data.json)
I've tried a lot of solutions here that revolve around the asset section in pubspec.yaml
name: hello_world
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
path_provider: ^0.4.1
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
assets:
- toonRepo/
uses-material-design: true
Am I going wrong somewhere very silly?
Cheers for any pointers you have.
Project Structure
Here is a temporary copy of the code if you want to take a peek.
Github
And here's a stack trace
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
Unable to load asset: toonRepo/data.json
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:67:33)
<asynchronous suspension>
#2 CachingAssetBundle.loadString.<anonymous closure> (package:flutter/src/services/asset_bundle.dart:162:56)
#3 __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:284:23)
The asset access works fine with the pubspec.yaml in your question.
new Text("Name: " + toon.info.name)),
fails because toon is null because it never got a value assigned.
You could use new Text("Name: " + (toon?.info?.name ?? 'foo')), to work around the exception.
If you add
widget.storage.getFileData('toonRepo/data.json').then((f) => print(f));
to _FlutterDemoState.initState(), you'll see that reading the asset works just fine.

Flutter play custom sound using audioplayers 0.7.7?

pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/Images/1.png
- assets/Images/MP3.mp3
Test.dart
Widget localAsset() {
return _tab([
Text("Click to play"),
_btn('Play', () => audioCache.play('assets\Images\MP3.mp3')),
]);
}
I am new to flutter, for my applications i want play two sounds mode(background sound ,button action sound), after referred from flutter package i have changed code like as above , when i used this widget in my material,i am getting below error,
E/flutter ( 2750): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 2750): Unable to load asset: assets/assetsImagesMP3.mp3
E/flutter ( 2750): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
Backslash are Windows-specific. Use slashes instead. Android is Unix-based and so is iOS
audioCache.play('assets/Images/MP3.mp3')