When I try to use an image, the code gives me the following error:
But the code is working only with another image. When I try to use this one, it fails.
This is the code:
Center(
child: Image.asset(
'assets/perigo.png'),
)
Pubspeck.yaml file:
assets:
- assets/
check your image ("perigo.png") is correct, Type of image etc.
This work for me. try:
stop the running app and re-run it. (Not restart)
If it's not,
set your Pubspeck.yaml file like this,
assets:
- assets/perigo.png
Related
I have 3 local json files that are similar. I want to load each of them at different times in flutter. Is there anyway to pass variables in future for doing this?
You can load anything that is included as an Asset in your app. So for example, you could put this in your pubspec.yaml:
assets:
- config/ordinary.json
- config/special.json
Then you could load either of those in your code, like this:
final config = await DefaultAssetBundle
.of(context)
.loadString('config/ordinary.json');
I have downloaded a file to getApplicationDocumentsDirectory().
Then I have inserted the file path to a SQLite database.
In this case the file is a png file, and I need to show it on a screen.
I am trying to do it as follows:
Container(color: Colors.grey[200],
child: Image.file(File(${snapshot.data![position].path})),
alignment: Alignment.center
)
I am geting an exception:
FileSystemException: Cannot open file, path=//var/mobile/Containers/Data/Application/B2663D60-9BEF-4FFF-9287-BFD3CE6EF8BE/Documents/AgdsBeviewlogomodesto.png
I have checked if the path from the downloaded file is equal to the path from the SQLite item value, and both are equal.
Downloaded file path print output:
flutter: path al archivo descargado /var/mobile/Containers/Data/Application/B2663D60-9BEF-4FFF-9287-BFD3CE6EF8BE/Documents/AgdsBeviewlogomodesto.png
SQLite path value :
path en docs: /var/mobile/Containers/Data/Application/B2663D60-9BEF-4FFF-9287-BFD3CE6EF8BE/Documents/AgdsBeviewlogomodesto.png
I have also tested putting that path as text directly into
Image.file(File("/var/mobile/Containers/Data/Application/B2663D60-9BEF-4FFF-9287-BFD3CE6EF8BE/Documents/AgdsBeviewlogomodesto.png"))
and it works.
I don´t find the reason for not showing the image when using the value snapshot.data![position].path, knowing that it is the same value.
In the exception, I can see that there is a leading / sign in the path which might be the problem.
FileSystemException: Cannot open file, path=//var/mobile/Containers/Data/Application/B2663D60-9BEF-4FFF-9287-BFD3CE6EF8BE/Documents/AgdsBeviewlogomodesto.png
After upgrade flutter with null safe i'm facing this error
'assets/images/bg111.svg',
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),```
Error:
════════ Exception caught by SVG ═══════════════════════════════════════════════
The following assertion was thrown while parsing AssetBundlePictureKey(bundle: PlatformAssetBundle#0293d(), name: "assets/images/bg111.svg", colorFilter: null) in _getDefinitionPaint:
Failed to find definition for url(#pattern0)
This occurs because you are using the element before defining it.
For me the solution was moving the entire defs tag and its content to immediately after the opening svg tag
Try below code hope its help to you. used flutter_svg: ^1.0.0 current version of svg dependency here.
Your widget:
SvgPicture.asset(
'assets/images/water.svg',
// height: MediaQuery.of(context).size.height,
// width: MediaQuery.of(context).size.width,
),
Your pubspec.yaml file
assets:
- assets/images/
Result screen->
As user #Mark Hardy said:
This arises in Android builds from a combination of:
Using compileSdkVersion 31,
With JDK8,
Having any Lambda style related code somewhere (else error may not happen).
The default android toolchains have moved to JDK11 now, you must use JDK11 when you change any of the Android API target versions from 30 to 31.
Semi duplicate of unrecognized Attribute name MODULE (class com.sun.tools.javac.util.SharedNameTable$NameImpl)
When using the Flutter SvgPicture package, I fall into the same problem.
I solve this issue by exporting the file from Figam as PDF and then converting the pdf file to SVG.
Here are the steps I follow:
Save as (.pdf) from Figma/Adobe XD.
Then go to Zamzar and convert the PDF file as SVG Image.
Use this image & Boom !!!
The problem is solved !!!
Bit late, but I had the same problem and fixed it by opening the svg and moving the ... to the top.
There are many lint warnings in different files of my project like:
Prefer const with constant constructors.
Use key in widget constructors.
...
Unnecessary string interpolation.
Is there a way to only fix a particular warning, something like
dart fix prefer_const_constructors
PS: I don't want to fix all the warnings, for that I can run dart fix --apply.
Yes, It is possible by changing lint rules. For time being, you have to add only rules which you want to fix and ignore all others.
Follow these steps
In the project, you have to create analysis_options.ymal file. The content of the file will look like this.
linter:
rules:
prefer_const_constructors: true
More details here
After that try to run dart fix, since only one lint rule is enabled it only gives you suggestions for that only.
To ignore a single line, you can add a comment above the line:
// ignore: non_constant_identifier_names
final NEW = 'NEW';
To ignore for the whole file, you can add a comment at the top of the file:
// ignore_for_file: non_constant_identifier_names
To ignore for the whole project, you can set the rule to false in your analysis_options.yaml file:
include: package:lints/recommended.yaml
linter:
rules:
non_constant_identifier_names: false
Refer this for more
Customizing static analysis
Setting up Lint Rules in Dart-Flutter
I can not replace the icon Matlab by another. I have yet to try several code recover on the internet, but it's always the same thing, the Java icon appears and sometimes none are displayed.
Would you another track?
thank you
Here one of the tested codes:
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
jframe=get(hObject,'javaframe');
jIcon=javax.swing.ImageIcon('icon.png');
jframe.setFigureIcon(jIcon);
initialize_gui(hObject, handles, false);
The code you show works for me. Are you sure the 'icon.png' file is located in the correct folder? Try specify the full path to the image:
jIcon = javax.swing.ImageIcon(fullfile(pwd,'icon.png'))