flutter pubspec.yaml deleted after updating - flutter

Hello experts I am facing very big issue I am made application in 2021 on flutter my application is still live on play store now I need update it, problem is that I updated my android studio flutter version 3.0. Now opening my old project which was made in 2021 after opening it my pubspec.yaml file is missing in the project, I don't no how to recover that file or repair it. They have a lot of dependencies included there is pubspec.lock file available but not pubspec.yaml please please help me i am in big check screen shot below
if i use flutter create command i am getting this errors

You can create a pubspec.yaml file on root directory or open the bottom terminal and try flutter create . it will provide default structure. Now to get pub package, check the import section and add on pubspec.yaml

If you have a backup then paste the pubspec.yaml file from it. Else take a backup of the project. Run flutter create . in the root directory. It will create the pubspec file in the project. Click on configure dart and add the flutter path then run the project. It will throw errors for the packages used manually enter packages in pubspec or you can try flutter pub add <packagename>

Related

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.

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.

I am not able to use other packages in dependencies in flutter

I have just started using flutter and I am using flutter packages like material.dart , cupertino.dart but when it come to use other packages like image_picker, english_words, I am not able to use it and I had declared packages with versions in dependencies in pubsec.yaml file. After when I write the import package name in the main file it shows a red line under it and the folder was also not created on the left side.
It seems the packages that were declared as dependencies in pubspec.yaml files are not yet downloaded.
Try running: flutter packages get from your project's root directory.
Sometimes it doesn't work even after the above command is executed, in such case close current project and reopen it.

Flutter web cannot use packages from mobile project

A few months ago I made an android application using flutter. The application requires various dependencies such as intl, cached network image, stopper, carousel_slider, etc.
Then right now I want to convert the project to flutter_web. Here are the steps that I did:
clone github web flutter
I run the command "flutter packages pub global activate webdev"
Then I edited pubspec.yaml and I adjusted it to pubspec.yaml in the previous project (android project)
Here is the contents of pubspec.yaml on the web flutter project:
name: flutter_web.examples.hello_world
environment:
  # You must be using Flutter> = 1.5.0 or Dart> = 2.3.0
  sdk: '> = 2.3.0-dev.0.1 <3.0.0'
dependencies:
  flutter_web: any
  flutter_web_ui: any
  stopper: ^ 1.0.1
dev_dependencies:
  build_runner: ^ 1.4.0
  build_web_compilers: ^ 2.0.0
dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web_ui
  provider:
    git:
      url: https://github.com/kevmoo/provider
      ref: flutter_web
When I run 'pub dev', an error occurs while resolving the package stopper. Then I tried to open github from the package stopper (https://github.com/aryzhov/flutter-stopper), after that I checked the files in the lib folder. There I found a file called stopper.dart. It turns out that in the file, still using
 import 'package: flutter / material.dart';
So that makes my pubspec error. Because the code should be replaced with
import 'package: flutter_web / material.dart';
Therefore, I tried to outsmart the problem by removing the dependency stopper on pubspec.yaml, then I created a stopper.dart file manually, then I saved it in the lib/mypackages folder. After that, I import stopper.dart from the lib/mypackages folder (it's no longer through the package).
The package stopper is just one of the packages that I use on my Android project. Actually there are many other packages that have the same problem as the package stopper. The point is I have to create the package files manually, then I change "package: flutter / ..." to "package: flutter_web /" manually, then I can import them.
What I want to ask, is there a more elegant and simple way?
Hi the instruction you are following is from an old repository here. As you can see this is discontinued. You can find the informaiton in the REadme.
Instead you should follow the instructions in this page. Read it once carefully and I would suggest to keep a backup of your main project and work on a copy.
First you will have to enable the flutter-web using flutter config --enable-web.
Then you will have to run flutter create .

How can I run an example from a Flutter package/library?

I have the following simple directory structure:
flutter_published
.idea
android
build
ios
lib
main.dart
flutter_published.iml
pubspec.lock
pubspec.yaml
network_to_file_image
.idea
example
main.dart
lib
network_to_file_image.dart
test
network_to_file_image.iml
pubspec.lock
pubspec.yaml
network_to_file_image is a package.
There are two main.dart files, one at flutter_published/lib/main.dart and
another at flutter_published/network_to_file_image/example/main.dart
I am able to run the first one, but not the one inside of the example directory under network_to_file_image. The second one gives me this error:
Launching example\lib\main.dart on Android SDK built for x86 in debug mode...
No application found for TargetPlatform.android_x86.
Is your project missing an android\AndroidManifest.xml?
Consider running "flutter create ." to create one.
Also, when the app is generated, what happens to the example and test directories of the packages I use? Are they included or removed from the final app that is deployed?
To solve this, instead of the main.dart file inside of the example directory, you need to create a complete Flutter application-type project inside of the example directory. Then, the example tab will point to the README.md file inside of that directory.
That example directory will have its own lib directory, containing a main.dart file. Since that file is now inside of an application-type directory it can be run.
Visit this repo to see how it works:
https://github.com/marcglasberg/async_redux/tree/master/example
Update:
To be clear, the example's pubspec.yaml file can reference its package by using a relative reference. For example, here is the dependencies section of the example dir of the async_redux package I mentioned:
dependencies:
http: ^0.13.1
async_redux:
path: ../
flutter:
sdk: flutter
Since the example dir is at the same level as the package's pubspec.yaml file, then the example's own pubspec.yaml is one level below it. Thus, it may reference the package itself by using a ../ path:
async_redux:
path: ../
example/main.dart only exists to be shown in https://pub.dartlang.org/packages/network_to_file_image#-example-tab-
The pub site is limited in how it finds content in the example directory to display in the Example tab.
cd to the directory and execute flutter create .. You should be able to run it afterwards
Go to the example folder of the repository of the package.
Open the lib folder and go to the main.dart file.
Above the void main() function, you can see the Run|Debug|Profile (pic below), click on the one you want to run the project as.
The example app will now run in your emulator.
The screenshot below is of the chewie package available on pub.dev