Error setting-up flutter_localizations package "Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'." - flutter

This error appears when I try to add language support to my flutter application:
Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.
I’m using flutter_localizations, the project is built with dart 2.7.0
It seems that flutter_localizations needs latest sdk which is dart 2.13.0
How can I fix this?

I had this same issue with import 'package:flutter_gen/gen_l10n/app_localizations.dart' in Visual Studio Code after updating to Flutter 2.5.
After closing the VS Code window and reopening it, the error was gone.
If that doesn't work, try closing and opening VS Code again.
Or restart the Dart Analysis Server by going to View > Command Palette and then typing Dart: Restart Analysis Server.
Credit goes to https://stackoverflow.com/a/68150402/4797855 and https://stackoverflow.com/a/68731436/4797855.

Open Command Palette and select Dart: Restart Analysis Server.

Just type in the project terminal flutter gen-l10n it will solve your problem.

Also, in the pubspec.yaml file, enable the generate flag. This is added to the section of the pubspec that is specific to Flutter, and usually comes later in the pubspec file.
# The following section is specific to Flutter.
flutter:
generate: true # Add this line

just in Your terminal run this
flutter pup add flutter_gen/gen_l10n
It fixed my app

I had this issue before, and I tried to solve it by adding charts_flutter to my pubspec.yaml but it didn't solve my.
Lucky me, charting library recently released a new version which is compatible with flutter 2.5. I didn't need to add anything to my pubspec(I removed chart_flutter from my ). just run the app even if the compiler shows an error saying Target of URI doesn't exist for the import line. The system is going to generate that file on runtime.

Be sure that there's an l10n.yaml file in your project root as follows.
Example
Demonstration variables
foldername = l10n
defaultIntlFile = intl_en.arb
importFileName = app_localizations.dart
Import
import 'package:flutter_gen/gen_l10n/importFileName';
l10n.yaml
arb-dir: lib/foldername
template-arb-file: intl_en.arb
output-localization-file: app_localizations.dart
Structure
lib/foldername/defaultIntlFile

The solution in my case:
"If you are using a package flutter_gen you need to remove it from pubscpec.yaml to resolve conflict." credit Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/gallery_localizations.dart'

Related

Flutter: MissingPluginException(No implementation found for method printPdf on channel net.nfet.printing)

guys!
I am developing a desktop POS application for a shop. The application should have a feature to print some docs and barcodes. I have used pdf package to generate pdfs, but I am having a trouble with installing and using the priting package on Windows.
The main problem is with isntallation. In the docs, it says you should add the following lines in
CMakeLists.txt
file:
...
set(PDFIUM_VERSION "4929" CACHE STRING "" FORCE)
set(PDFIUM_ARCH "x64" CACHE STRING "" FORCE)
...
I am very confused in which CMakeLists.txt I shall put, because flutter's windows folder includes multiple files with the same name and extension. (windows\CMakeLists.txt, windows\runner\CMakeLists.txt, windows\flutter\CMakeLists.txt)
I have put the same piece of code into these different files, but none of them worked.
It always gives some errors like below:
errors
The thing I wanted to accomplish is to just print a generated PDF:
code
I'm having the same issue
What I do is
Flutter clean
Flutter pub get
Uninstall the previous application
Run the app again
And it worked
go to your terminal and type the following commands.
Flutter clean
Flutter pub get
now close the app
build the app again
hope this works for you. thanks.

After flutter new project creation I can't locate the main dart file to start programming

I have installed Android Studio and flutter successfully. When I run flutter doctor in command prompt it gives me [all green ticks in these brackets].
The question is that after the creation of a new flutter project on the right-hand side of the screen under the project I am unable to see/locate any dart main file to write code. For further clarification, you can see the attached image below.
Unable to locate the dart file to write code in the project hierarchy:
I have 0 ideas what is still missing in the configuration of Flutter / Android Studio
Well, I figured out why pubspec.yaml and main.dart was not in my project due to the older version of flutter. I downloaded the latest version flutter_windows_2.2.2-stable, created a new flutter project, and included the flutter SDK path of flutter_windows_2.2.2-stable which resolved all my problems. Kindly, make sure whoever wants to start Mobile Application development in Android Studio + Flutter + Dart always download the latest version of everything.
Recent Experiment:
After downloading the latest version of Flutter still, I was unable to get the pubspec.yaml and main.dart files in my Android Studio Project, so the solution is below:
where you have extracted your flutter_windows_2.2.2-stable remember the directory path like E:\src\flutter_windows_2.2.2-stable which is in my scenario.
******************* CMD WORK *******************
Open cmd(Command Prompt) by default you will be in the directory like C:\Users\UserName\
Now go to the path E:\src and to navigate write E: hit enter, now you will be in the E: directory. Write cd E:\src hit enter.
type flutter create project_name ( make sure whenever you withe the name of the project it should be like this my_first_app in this format you name the projects with proper naming convention in flutter [word_word_word_word] ) then hit enter, wait for a while it will create a new flutter project for you including pubspec.yaml and main.dart files + necessary files to be imported.
Reference for naming convention in flutter (https://medium.com/flutter-community/file-and-folder-structure-in-flutter-967b8be3155e#:~:text=Flutter%20doesn't%20have%20a,letters%20and%20underscores%20between%20words.&text=When%20naming%20folders%2C%20you%20want,them%20very%20direct%20and%20clear.)
Right now after the creation of a project(Flutter) in Android Studio you are unable to see/locate the pubspec.yaml and main.dart files use cmd for the project creation which worked in my scenario.

Flutter extension-methods not working, it says "undefined class" and "requires the extension-methods language feature"

I'm slowly building my personal website over at dlblack.dev, and I'm trying to spice it up a little bit. For example, from a computer (rather than a tablet or phone since they don't have mouse pointers), if you hover over any of the clickable items, it doesn't change your mouse pointer to indicate it's clickable, and the clickable object doesn't change at all. I've decided to follow this FilledStacks tutorial, but it doesn't mention anything about fixing this problem.
Essentially what's happening is when I get ~2.5 mins through the tutorial video (where he writes the skeleton extension class) and try to duplicate it, VS Code redlines almost the entire class declaration aside from the name. What I'm writing is the exact same thing as what he has on screen at 2:26, and here's my code:
import 'package:flutter/material.dart';
import 'dart:html' as html;
extension HoverExtension on Widget{
}
"extension", "on", and "Widget" are all redlined when I do this. When I hover over "extension", it says the following:
Undefined class 'extension'.
Try changing the name to the name of an existing class, or creating a class with the name 'extension'. dartundefined_class
This requires the 'extension-methods' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 2.6 or higher, and running 'pub get'. dart(experiment_not_enabled)
The first thing I did was change my minimum SDK constraint to 2.6.0 in my pubspec.yaml file. I then changed it to 2.7.0 because a lot of people online say extensions were released in Dart 2.7. I've done a lot of Googling on the subject but no one seems to have the same problem as me: I have no analysis_options.yaml file. I created one, and put only this in its contents:
include:
analyzer:
enable-experiment:
- extension-methods
linter:
In theory, I believe that should fix my problem once I run flutter pub get from the command line in my root folder; it doesn't. I have no idea what's wrong. Any suggestions?
In Android Studio solving this problem requires three steps:
Update SDK version in pubspec.yaml (must be 2.6.0 or higher)
environment:
sdk: ">=2.7.0 <3.0.0"
Tools -> Flutter -> Flutter Clean
Close project and reopen it (eg. File -> Close project)
For the changes in pubspec.yaml and analysis_options.yaml to take place, you have to restart the Dart Analysis Server. In VSCode, that's as simple as Ctrl+Shift+P -> Reload Window.
I had to do flutter clean, then close and re-open VSCode.
I had a similar problem with the "extensions" feature in Dart (on Windows) ... I was getting "undefined class", and the message saying that I needed to use the "experimental" Dart settings. It seems that I had two Dart installations, one in "c:\Program Files" and one in "c:\tools\dart-sdk". I removed the version under "Program Files". I also ran "choco uninstall dart-sdk" and "choco install dart-sdk", and made sure that the version was correct (using "dart --version") after the install. The command "where dart" should display "c:\tools\dart-sdk-bin-dart.exe" after the choco install. When I went back into my Flutter project (using Android Studio) it said that I didn't have Dart support for my project, and I just had to enter the Dart SDK location.
if tombroz's solution won't work then
1.Tools -> Flutter -> Flutter Clean
2.Tools -> Flutter ->Pub get
3.File -> Invalidate cache/Restart -> Invalidate cache and Restart
I just had to run flutter clean et voila.

The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated

I'm running a dart only test in intellij and receiving the following error:
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
I have tried pub get a number of times. Any ideas? I'm on the dev branch of Flutter (anything using Dart 2.7 pretty much fails with the same or a similar error message).
Edit
I think that if you have a path reference dependency in the pubspec.yaml file it will fail.
Anything like the following fails with the above message if you try to run a dart test in IntelliJ.
dependencies:
test_dependency:
path: ../test_dependency
I'm not suggesting this is a fix for everyone, but it did resolve my particular situation.
Just ran into this error after upgrading flutter from 1.22.6 to 2.0.2 and trying to use build_runner: ^1.12.2 and json_serializable: ^4.1.0 to generate json serialization/deserialization classes & methods.
The problem is apparently related to the pub package when used with relative paths for packages as noted in the following github issues:
https://github.com/dart-lang/pub/issues/2806
https://github.com/dart-lang/pub/pull/2830
One of the commenters in issue 2806 mentioned running flutter create . inside the flutter project folder which rebuilds .dart_tool/package_config.json, adding any missing entries, solving the problem.
No one solved this problem so far?
I've found a staightforward solution and it works fine for me.
You need to close your IDE (VSCode in my case), make sure that is completely closed using process-monitor.
Then open a terminal window manualy in your project folder and run "flutter pub get"
After that just start your IDE normaly and ewerything will work fine.

Flutter run says '...dependencies could not be established' for the meterial.dart library

I am new to flutter.io and trying to create my first flutter app according to the following guide
https://codelabs.developers.google.com/codelabs/first-flutter-app-pt1/#2
I used terminal command flutter run to start my application and then found an error as follows.
Your application could not be compiled, because its dependencies could not be established.
The following Dart file:
./startup_namer/lib/main.dart
...refers, in an import, to the following library:
/opt/flutter/packages/flutter/lib/meterial.dart
Unfortunately, that library does not appear to exist on your file system.
Couldn't find more details on how to resolve this issue.I am gussing that i should install this library package within my setup.What is the easiest method to install flutter library package from terminal?
Note: i created the app using command flutter create startup_namer
Judging by the error message you have mis-spelled the package in the import statements meterial.dart
It should be:
import 'package:flutter/material.dart';
Note: You may run into same error if you were to change the variable "name: myapp" in your pubspec.yaml file with "import 'package:myapp/settings.dart';" as the custom package in the main.dart file as was intended to add "comanyName" text to the app launcher icons. Fix: changed back to "name: myapp" removed the error