Exception whilst trying to display an image in flutter - dart

I am trying to display an image in a flutter app.
I have added an images directory and have a file in that directory called iu.png.
In pubspec.yaml I have:
assets:
- images/iu.png
in main.dart I have:
```
child: new Column(
children: <Widget>[
new Text('Image Demo'),
new Image.asset('images/iu.png'),
],
),
```
When I run the code in either an Android or iOS simulator I get the following exception:
I/flutter ( 9252): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE
╞════════════════════════════════════════════════════ I/flutter (
9252): The following assertion was thrown resolving an image codec:
I/flutter ( 9252): Unable to load asset: images/iu.png I/flutter (
9252): I/flutter ( 9252): When the exception was thrown, this was the
stack: I/flutter ( 9252): #0 PlatformAssetBundle.load
(package:flutter/src/services/asset_bundle.dart:221:7) I/flutter (
9252): I/flutter ( 9252): #1
AssetBundleImageProvider._loadAsync
(package:flutter/src/painting/image_provider.dart:427:44) I/flutter (
9252): I/flutter ( 9252): #2
AssetBundleImageProvider.load
(package:flutter/src/painting/image_provider.dart:412:14) I/flutter (
9252): #3 ImageProvider.resolve.. (package:flutter/src/painting/image_provider.dart:266:86)
I/flutter ( 9252): #4 ImageCache.putIfAbsent
(package:flutter/src/painting/image_cache.dart:143:20) I/flutter (
9252): #5 ImageProvider.resolve.
(package:flutter/src/painting/image_provider.dart:266:63) I/flutter (
9252): (elided 8 frames from package dart:async) I/flutter ( 9252):
I/flutter ( 9252): Image provider: AssetImage(bundle: null, name:
"images/iu.png") I/flutter ( 9252): Image key:
AssetBundleImageKey(bundle: PlatformAssetBundle#54de0(), name:
"images/iu.png", scale: I/flutter ( 9252): 1.0) I/flutter ( 9252):
════════════════════════════════════════════════════════════════════════════════════════════════════
I am using the latest flutter master and flutter doctor output is:
Doctor summary (to see all details, run flutter doctor -v): [✓]
Flutter (Channel master, v0.10.2-pre.21, on Mac OS X 10.13.6 17G65,
locale
en-GB) [✓] Android toolchain - develop for Android devices (Android SDK 28.0.3) [✓] iOS toolchain - develop for iOS devices
(Xcode 10.0) [✓] Android Studio (version 3.2) [✓] IntelliJ IDEA
Community Edition (version 2018.2.3) [✓] Connected device (2
available)
Anyone have any clues?

I had the same problem, but if I put images direcly inside assets folder its working justg fine. In this case you also need to change pubspec.yaml (assets: -ui.png) and then you can load the image with Image.asset('ui.png').

make sure your indentation is done properly in your pubspec.yaml.
Subcategory should be indented two spaces than it's parent category.
PS: The dash counts as the first character in subcategory.
According to flutter docs Adding assets and images indentation should be as following:
flutter:
assets:
- assets/my_icon.png
- assets/background.png

Specify Image path as follows
Image.asset("assets/images/car_android.png")
OR
Image(image: AssetImage("assets/images/car_android.png"))
The problem is flutter can't recognize where your image is exactly stored.
If the problem continues then try to do HOT RESTART this will solve your problem.
Update your pubspec.yaml file before this
If you update pubspec.yaml file then run flutter pub get to update the libraries if your IDE doesn't update it automatically.

Related

error: Build input file cannot be found: '/Users/GoogleService-Info.plist' (in target 'Runner' from project 'Runner')

I'm trying to take the iOS build of a Flutter project. No matter what I try it just gives me the following error:
error: Build input file cannot be found: '/Users/GoogleService-Info.plist' (in target 'Runner' from project 'Runner')
This is the set of commands I am trying to get the build with:
flutter pub get
flutter clean
flutter build ios (this gives the above error)
Here is my flutter doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.16.3-pre.67, on Mac OS X 10.15.3 19D76, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.43.2)
[!] Connected device
! Doctor found issues in 1 category.
The flutter build ios --verbose ends with following error:
Encountered error while building for the device.
#0 throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1 BuildIOSCommand.runCommand (package:flutter_tools/src/commands/build_ios.dart:93:7)
<asynchronous suspension>
#2 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:722:18)
#3 _rootRunUnary (dart:async/zone.dart:1155:38)
#4 _CustomZone.runUnary (dart:async/zone.dart:1048:19)
#5 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
#7 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
#8 Future._completeWithValue (dart:async/future_impl.dart:526:5)
#9 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:556:7)
#10 _rootRun (dart:async/zone.dart:1147:13)
#11 _CustomZone.run (dart:async/zone.dart:1040:19)
#12 _CustomZone.runGuarded (dart:async/zone.dart:942:7)
#13 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:982:23)
#14 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#15 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#16 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)
Here is the image of the folder structure. As you can see, there is no 'Users' folder that holds the Google plist. So, it is quite confusing why would the script try to copy the plist from a non-existing directory. Any advice to fix this would be highly appreciated. TIA :-)
Remove the GoogleService-Info.plist and then again add the file into the Runner directory using Xcode, then choose copy items if needed and add to target checkmark. I hope this will solve your problem.
Make sure the name of the file is correct, i.e: "GoogleService-info.plist"
Add it to the project in mac finder under the project name and then drag it into the project to reference it.
Finally, go to the file inspector for the plist file and tick the box under target membership to include it as part of the project.
Reference

Can't run any other flutter app except for one

I've cloned a new flutter project from git
When I try to run I get the following error
Error: Could not resolve the package 'application_flutter_todo' in 'package:application_flutter_todo/utils/constants/api.dart'.
../../.pub-cache/git/flutter_maximo_api-35d1fef13c59a0e7fb70a20916adf1f9d26eac02/lib/src/maximo_api.dart:5:8: Error: Not found:
'package:application_flutter_todo/utils/constants/api.dart'
import 'package:application_flutter_todo/utils/constants/api.dart';
^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Aapplication_flutter_todo%2Futils%2Fconstants%2Fapi.dart; message=StandardFileSystem only supports file:* and data:*
URIs)
#0 StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1 asFileUri (package:vm/kernel_front_end.dart:604:37)
<asynchronous suspension>
#2 writeDepfile (package:vm/kernel_front_end.dart:799:21)
<asynchronous suspension>
#3 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:472:15)
<asynchronous suspension>
#4 _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:38:22)
#5 starter (package:flutter_frontend_server/server.dart:149:27)
#6 main (file:///b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)
#7 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:32)
#8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
Failed to build bundle.
Failed to package /Users/Mohammad/Gemba/application_traxxion.
Could not build the precompiled application for the device.
It appears that your application still contains the default signing identifier.
Try replacing 'com.example' with your signing id in Xcode:
open ios/Runner.xcworkspace
Note that the current project doesn't have the import 'package:application_flutter_todo' statement.
That statement belongs to another app and is not in the current project that I'm trying to run.
I've tried,
1- flutter clean
2- updating flutter
3- updating packages
4- cleaning the product
5- cleaning the project
6- running the project from terminal, visual studio code, xcode all three gave the same result.
Nothing of the above have worked.
As the error implies, you should change your package name and BundleId for Android & iOS respectively. You shouldn't be using the default ones.
You can find how to do so here.

Dart FFI fails loading dynamic library in MacOS

I am trying to build flutter desktop application in MacOS and trying call C++ code using dart FFI. I have used this GitHub project as template and change some source code to call C++ library. I am able to run this project if I do not use FFI.
https://github.com/google/flutter-desktop-embedding
ERROR :
flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following ArgumentError was thrown building MyHomePage(dirty, state: _MyHomePageState#86c2f):
flutter: Invalid argument(s): Failed to load dynamic library (dlopen(/usr/lib/structs.dylib, 1): image not
flutter: found)
flutter:
flutter: The relevant error-causing widget was:
flutter: MyHomePage
flutter: file:///Users/rmazumder/VisualCode-Workspace/flutter-desktop-embedding-master/example/lib/main.dart:39:13
flutter:
flutter: When the exception was thrown, this was the stack:
My Flutter and Dart version:
rmazumder$ flutter --version
Flutter 1.12.15-pre.12 • channel master •
https://github.com/flutter/flutter.git
Framework • revision b2a36ffcd2 (22 hours ago) • 2019-11-26 11:45:51 -0500
Engine • revision e136d637a8
Tools • Dart 2.7.0

Dart Error: error: import of dart:mirrors with --enable-mirrors=false

.yaml file bellow:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
fluttertoast: ^2.0.9
dio: ^1.0.6
json_serializable: ^2.0.0
dev_dependencies:
build_runner: ^1.0.0
json_annotation: ^2.0.0
when I run:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
D/OpenGLRenderer( 5350): HWUI GL Pipeline
I/OpenGLRenderer( 5350): Initialized EGL, version 1.4
D/OpenGLRenderer( 5350): Swap behavior 1
D/ ( 5350): HostConnection::get() New Host Connection established
0xa12b3ec0, tid 5379
D/EGL_emulation( 5350): eglCreateContext: 0xa127cf60: maj 2 min 0 rcv 2
D/ ( 5350): SurfaceInterface::setAsyncMode: set async mode 1
D/EGL_emulation( 5350): eglMakeCurrent: 0xa127cf60: ver 2 0 (tinfo
0xa177fe80)
E/flutter ( 5350): [ERROR:flutter/shell/common/shell.cc(188)] Dart Error:
error: import of dart:mirrors with --enable-mirrors=false
E/flutter ( 5350): [ERROR:flutter/shell/common/engine.cc(176)] Could not
prepare to run the isolate.
E/flutter ( 5350): [ERROR:flutter/shell/common/engine.cc(123)] Engine not prepare and launch isolate.
E/flutter ( 5350):
[ERROR:flutter/shell/platform/android/android_shell_holder.cc(167)] Could not launch engine in configuration.
i know the problem is that 'json_serializable' but i didn't know how to resolve it. or is there any way to transform between model and json
I did stumble across your post on my own search after solutions with your problem.
I assume that you want to use json_serializable for your own sourceCode creation.
If this is the case you should have
json_serializable: ^2.0.0
under the dev_dependencies.
Explanation
json_serializable does use dartlang/source_gen internally.
source_gen in turn does reference dart:mirrors, which is not supported in flutter (as told in this post).
So long story in short:
- through removing the dependency on json_serializable from your "build" dependencies you remove the dependency on mirrors which is stopping your flutterBuild.
i know the problem is that 'json_serializable' but i didn't know how to resolve it. or is there any way to transform between model and json
I did not really got that part.
At least for me this is not enough information to provide help on your modelgeneration.
Could try if you post a class in which you use json_serializable and the generated partial class.
I had similar problem. I was using appengine plugin with MethodChannel and once I removed appengine dependency it all worked fine.

Creating a directory list in windows using Dart

I am trying to create a directory list on windows using dart but I get an error
Here is my code
void listerine(Directory pat){
//Directory root = new Directory(pat);
//var root = Directory.systemTemp;
pat.list(recursive: true, followLinks: false).listen((FileSystemEntity entity){
main(List<String> arguments){
var root = new Directory("C:\\");
print(root);
listerine(root);
}
Btw I am using android studio as an IDE.
I gives me this error.
I/flutter ( 7224): Directory: 'C:\'
E/flutter ( 7224): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 7224): FileSystemException: Directory listing failed, path = 'C:\/' (OS Error: No such file or directory, errno = 2)
E/flutter ( 7224): #0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1114:29)
E/flutter ( 7224): #1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 7224): #2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
You have the question tagged as flutter but seems you are asking about a pure Dart program?
This code
import 'dart:io';
void listerine(Directory pat) async {
await for (var v in pat.list()) {
print(v);
}
}
main() {
listerine(new Directory("C:\\"));
}
produces what you'd expect on Windows, namely
Directory: 'C:\$Recycle.Bin'
Directory: 'C:\$WINDOWS.~BT'
Directory: 'C:\Apps'
...
Flutter uses a modified version of the Dart SDK replacing html support with the mobile rendering engine (skia).
The majority of Dart code can run in both versions, but not all. This means that you can re-use packages in Dart VM applications and in Flutter applications - but again not all. In particular, interacting with the browser or the platform are only available in their respective versions.
To interact with the Windows file system, you need the Dart VM version. Download this separately. As Günter says, to interact with the mobile file system in Flutter, use path_provider.

Resources