I tried everything but nothing seems to work. According to me, the path of the image is correct. (though I have attached an image for reference). This is the error I am getting -
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: start.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:225
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:668
#2 AssetBundleImageProvider.load
package:flutter/…/painting/image_provider.dart:651
#3 ImageProvider.resolveStreamForKey.<anonymous closure>
package:flutter/…/painting/image_provider.dart:504
...
Image provider: AssetImage(bundle: null, name: "start.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#2bd13(), name: "start.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════
this is **pubspec.yaml*-
name: foodfast
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
splashscreen: ^1.3.5
cupertino_icons: ^1.0.0
firebase_auth: ^0.20.0+1
cloud_firestore: ^0.16.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/start.png
sign_in.dart
import 'package:flutter/material.dart';
class SignIn extends StatefulWidget {
#override
_SignInState createState() => _SignInState();
}
class _SignInState extends State<SignIn> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text('sign in'),
),
backgroundColor: Colors.white,
body: Center(
child: ListView(
children: <Widget>[
Image(image: AssetImage('start.png'), fit: BoxFit.cover),
new Text('text below image')
],
)),
);
}
}
You need to add your path of image first i.e. assets and then add image name
Image(image: AssetImage('assets/start.png'), fit: BoxFit.cover),
Provide the full path even if you have already given it in pubspec.yaml.
Hence, it should be 'assets/start.png'
Use full path like 'assets/start.png' in your image path.
Image(image: AssetImage('assets/start.png'), fit: BoxFit.cover),
Try changing the path from
AssetImage("/image/start.png")
to
AssetImage("./image/start.png")
(. means go to the highest folder level)
This worked for me!
Related
Ive created a simple flutter program to test out the plugin on flutter. ive set up a simple unity project with a button and imported it using the plugin to the flutter project. everything builds up correctly and my app runs, however the app crashes upon loading the UnityWidget
To Reproduce
Steps to reproduce the behavior:
create simple app in unity and flutter
exported unity as per instructions on Readme
moved unityLibrary from 'project Root/unity/android' to 'project Root/android' in order to fix unityLibrary not found build error
UnityWidgetController? overallController;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Route'),
),
body: SafeArea(
top: true,
bottom: true,
child: Stack(
children: [
UnityWidget(
onUnityCreated: onUnityCreate,
borderRadius: BorderRadius.zero,
),
],
),
),
);
}
void onUnityCreate(UnityWidgetController controller) {
overallController = controller;
controller.postMessage("ButtonManager", "setFromFlutter", "message");
}
**Unity (please complete the following information): ver 2020.3.5f1
OS: MacOS BigSur 11.4 (20F71)
Smartphone (please complete the following information):
OnePlus 5T Android 10
heres the error message
W/Gralloc3(31563): mapper 3.x is not supported
I/IL2CPP (31563): JNI_OnLoad
E/_flutter_widge(31563): Invalid ID 0x00000000.
D/AndroidRuntime(31563): Shutting down VM
E/AndroidRuntime(31563): FATAL EXCEPTION: main
E/AndroidRuntime(31563): Process: com.example.unity_flutter_widget, PID: 31563
E/AndroidRuntime(31563): android.content.res.Resources$NotFoundException: String resource ID #0x0
E/AndroidRuntime(31563): at android.content.res.Resources.getText(Resources.java:367)
E/AndroidRuntime(31563): at android.content.res.Resources.getString(Resources.java:460)
E/AndroidRuntime(31563): at com.unity3d.player.UnityPlayer.GetGlViewContentDescription(Unknown Source:20)
E/AndroidRuntime(31563): at com.unity3d.player.UnityPlayer.<init>(Unknown Source:271)
E/AndroidRuntime(31563): at com.xraph.plugin.flutter_unity_widget.UnityPlayerUtils$Companion$createPlayer$1.run(UnityPlayerUtils.kt:45)
E/AndroidRuntime(31563): at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime(31563): at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime(31563): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(31563): at android.app.ActivityThread.main(ActivityThread.java:7697)
E/AndroidRuntime(31563): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(31563): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
E/AndroidRuntime(31563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
D/ViewRootImpl[MainActivity](31563): windowFocusChanged hasFocus=false inTouchMode=true
I/Process (31563): Sending signal. PID: 31563 SIG: 9
Lost connection to device.
Exited (sigterm)
After a few days of googling, i managed to find the answer.
After exporting to android, i needed to enter this
<string name="game_view_content_description">Game view</string>
into the styles.xml file, within the resources tag
it is located in unityLibrary/src/main/res/values
Am new to flutter and was trying around Firebase, but the app doesn't initialize Firebase on release
it throws an error, yet it works wen you just run the app. Am using android studio
** E/flutter (12950): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: MissingPluginException(No implementation found
for method Firebase#initializeC ore on channel
plugins.flutter.io/firebase_core)
E/flutter (12950): #0 MethodChannel._invokeMethod
(package:flutter/src/services/platform_channel.dart:156) E/flutter
(12950): E/flutter (12950): #1
MethodChannel.invokeListMethod
(package:flutter/src/services/platform_channel.dart:344) E/flutter
(12950):
E/flutter (12950): #2 MethodChannelFirebase._initializeCore
(package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30)
E/flutter (12950):
E/flutter (12950): #3 MethodChannelFirebase.initializeApp
(package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75)
E/flutter (12950):
E/flutter (12950): #4 Firebase.initializeApp
(package:firebase_core/src/firebase.dart:44) E/flutter (12950):
E/flutter (12950): #5 main
(package:ug_campus_papers_example/main.dart:13) E/flutter (12950):
E/flutter (12950):
**
Line 13 is the await Firebase.initializeApp();
My Main file is
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'App1 Test',
home: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (BuildContext context, AsyncSnapshot<User> snapshot) {
if (snapshot.hasData) {
User user = FirebaseAuth.instance.currentUser;
return Make1(user: user,);
} else
return SignInScreen();
},
),
);
}
}
The pubspec.yaml file is as below
name: ug_camp_example
description: My Flutter app 1.
version: 3.0.1+3
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
firebase_core: "^0.7.0"
firebase_storage: "^7.0.0"
firebase_auth: "^0.20.1"
cloud_firestore: "^0.16.0+1"
ug_camp:
path: ../
cupertino_icons: ^1.0.2
google_fonts:
provider:
file_picker: ^1.1.1
flutter_plugin_pdf_viewer:
sqflite:
path:
flutterwave:
flutter_launcher_icons: ^0.7.4
dev_dependencies:
flutter_test:
sdk: flutter
flutter_icons:
image_path: "assets/images/apptest1.png"
android: true
ios: true
flutter:
uses-material-design: true
Please try the following:
Update your firebase packages to the latest versions. You're very outdated.
Ensure you've added your google-services.json to the project.
You mentioned you are using Android Studio, although are you running on Android or iOS? I can provide more instructions depending on the platform.
Used Plugin for the code
native_pdf_view: ^4.0.1
Sample code where is am getting error, I am able to use pdf file from assets but not able to load pdf from local storage
return Container(
child: PdfView(
controller:
// sample,
PdfController(
document: PdfDocument.openFile(widget.path),
),
onDocumentLoaded: (document) {
setState(() {
isLoaded = true;
});
},
pageLoader: Center(child: CircularProgressIndicator()),
),
);
error, it says the file was not found but this file path was extracted from the existing file
D/PDF_RENDER( 585): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf
D/PDF_RENDER( 585): OpenAssetDocument. Created file: /data/user/0/com.example.doc_holder/cache/992d7c88890d40268ae7ac4103bf96ba.pdf
D/PDF_RENDER( 585): OpenFileDocument. File: /data/user/0/com.example.doc_holder/cache/992d7c88890d40268ae7ac4103bf96ba.pdf
D/PDF_RENDER( 585): OpenFileDocument. File: /storage/emulated/0/Doc_Holder/c4611_sample_explain.pdf
════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building PdfView(dirty, state: _PdfViewState#6990d):
Null check operator used on a null value
The relevant error-causing widget was
PdfView
lib/const/pdf.dart:23
When the exception was thrown, this was the stack
#0 _PdfViewState._buildLoaded
package:native_pdf_view/src/native_pdf_view.dart:172
#1 _PdfViewState.build
package:native_pdf_view/src/native_pdf_view.dart:205
#2 StatefulElement.build
package:flutter/…/widgets/framework.dart:4683
#3 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4566
#4 StatefulElement.performRebuild
package:flutter/…/widgets/framework.dart:4738
...
Please try any of them
pdf: ^3.3.0,
flutter_full_pdf_viewer: ^1.0.6,
syncfusion_flutter_pdfviewer: ^19.1.58-beta,
syncfusion_flutter_pdfviewer_platform_interface: ^19.1.58-beta
When trying to run a url on browser with url_launcher plugin, I am getting this error on the release build on android. IOS and the android debug variant works fine.
E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method canLaunch on channel plugins.flutter.io/url_launcher)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157)
<asynchronous suspension>
#1 canLaunch (package:url_launcher/url_launcher.dart:124)
<asynchronous suspension>
#2 _HomeWidgetState.launchURL (package:pool_inspection/src/pages/home/home.dart:323)
<asynchronous suspension>
Here's my code
DialogButton(
color: Color(0xFF0B9CDA),
child: Text(
"Login Now",
style: TextStyle(
color: Colors.white, fontSize: 18),
),
onPressed: () {
setState(() {
launchURL();
});
},
)
Method for url launch
Future<void> launchURL() async {
const url = 'https://sometesturl.com';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
url_launcher version
url_launcher: ^5.7.10
Whats the issue I am unable to trace. I have already tried flutter clean,flutter pub get, Invalidate Cache/Restart as suggested by other answers.
I am building a flutter app and an asset image won't load when I run the app on my phone, but it loads fine when I run the app on the emulator.
Here's the error I get:
> I/flutter (26364): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE
> ╞════════════════════════════════════════════════════ I/flutter
> (26364): The following assertion was thrown resolving an image codec:
> I/flutter (26364): Unable to load asset: images/diamond.png I/flutter
> (26364): I/flutter (26364): When the exception was thrown, this was
> the stack: I/flutter (26364): #0 PlatformAssetBundle.load
> (package:flutter/src/services/asset_bundle.dart:221:7) I/flutter
> (26364): <asynchronous suspension> I/flutter (26364): #1
> AssetBundleImageProvider._loadAsync
> (package:flutter/src/painting/image_provider.dart:464:44) I/flutter
> (26364): <asynchronous suspension> I/flutter (26364): #2
> AssetBundleImageProvider.load
> (package:flutter/src/painting/image_provider.dart:449:14) I/flutter
> (26364): #3 ImageProvider.resolve.<anonymous closure>.<anonymous
> closure>.<anonymous closure>
> (package:flutter/src/painting/image_provider.dart:316:48) I/flutter
> (26364): #4 ImageCache.putIfAbsent
> (package:flutter/src/painting/image_cache.dart:160:22) I/flutter
> (26364): #5 ImageProvider.resolve.<anonymous closure>.<anonymous
> closure> (package:flutter/src/painting/image_provider.dart:316:25)
> I/flutter (26364): (elided 13 frames from package dart:async)
> I/flutter (26364): I/flutter (26364): Image provider:
> AssetImage(bundle: null, name: "images/diamond.png") I/flutter
> (26364): Image key: AssetBundleImageKey(bundle:
> PlatformAssetBundle#5b025(), name: "images/diamond.png", I/flutter
> (26364): scale: 1.0) I/flutter (26364):
> ════════════════════════════════════════════════════════════════════════════════════════════════════
And here's my pubspec.yaml
flutter:
uses-material-design: true
assets:
- images/
Here's main.dart:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blueGrey[900],
title: Text('Picture Motivation'),
),
body: Center(
child: Image(
image: AssetImage('images/diamond.png'),
),
),
),
),
);
}
What's very confusing is why the image is loading correctly on the emulator and not on the physical device. Any clue?
Thanks a lot.
Do this step by step, and this should work just fine. Basically you're doing it in wrong way.
Put the images in the assets folder, so the root is assets/diamond.png
Or if you have another folder in your assets folder, images, then the root is assets/images/diamond.png
pubspec.yaml
flutter:
uses-material-design: true
//you have to give the proper path in order to get the image in your UI
assets:
- assets/images/diamond.png
UI Code:
//this is how your image calling work, you just have to copy the path, same as pubspec.yaml
Center(
child: Image(
image: AssetImage('assets/images/diamond.png'),
)
)
I am sure you will be able to get the image now. Let me know if that helps.