Reference Local Path Package in Dart-Web Application - flutter

I sucessfully split up a flutter mobile application in to packages. One package is referenced by the flutter mobile app by using the following in the pubspec.yaml:
app:
path: /path/app
The fultter app builds and runs just fine and no problem is reported by the IDE (visual code) when it does the 'pub get'
When I do the same thing in the web-project the IDE complains on 'pub get' with:
Error on line 8, column 5 of pubspec.yaml: A version constraint must be a string.
When trying to build web project by issuing the command:
webdev build
I get the following error:
build_web_compilers:entrypoint on web/main.dart (cached): Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).
I even tried to use Windows native top level path (C:\path\package) but without a changed outcome. It seems that webdev does not support local path packages like described by the official PackageDependencies | Dart manual page.

When using shorthand and creating the web project it does not create a dependencies section in the pubspec.yaml file. I added another dependency (package) right under the environment section where the SDK is also configured.
It does not complained about the package dependency being under environment but it complains about a package dependency that has no version but a path.
I only noticed when I used a symlink to add the lib's source folder (lib) directly to the web project as it kept complaining about not finding this said package dependency.
Checking the packages file the package was not mentioned and in the pubspec.lock file the package was listed under the 'sdks:' section.
By creating a 'dependencies:' section and putting both dependencies under it, it now works as intended... . Case closed!

Related

Flutter | Error: Couldn't resolve the package

I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.

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.

Tried archiving flutter project with no disc space left, can't fix errors

Question upfront: How can I thoroughly clean/repair my flutter project to allow it to run/build again?
I had been building and archiving (in Xcode) flutter projects without issue until just now.
My computer ran out of disc space mid archive and forced it to stop with "nonzero exit code".
I deleted a bunch of things on the computer to make space, and now it says there is >100gb left.
I was due for a flutter upgrade, so I ran flutter upgrade, which completed without error.
I closed android studio and Xcode and restarted my computer.
I ran flutter clean as well as clean within Xcode.
I can no longer run the app within flutter or run/archive within Xcode.
The exact errors seem variable, but here are some of them that I see:
Running from Xcode:
.../ios/Flutter/Flutter.framework/Headers/FlutterPlugin.h:292:13: Cannot find protocol declaration for 'FlutterTextureRegistry'; did you mean 'FlutterPluginRegistry'?
.../ios/Flutter/Flutter.framework/Headers/FlutterEngine.h:54:38: Cannot find protocol declaration for 'FlutterTextureRegistry'; did you mean 'FlutterPluginRegistry'?
.../.pub-cache/hosted/pub.dartlang.org/in_app_purchase-0.3.1+2/ios/Classes/FIAPReceiptManager.m:13:9: Could not build module 'Flutter'
Running from Flutter (I can't paste all of the errors... way too long):
^~~~~~~~~~~~~~~~~~~~~~
FlutterPluginRegistry
While building module 'Flutter' imported from .../.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/ios/Classes/FLTPathProviderPlugin.h:5:
In file included from :1:
In file included from .../Documents/Flutter/patient_medical_record/ios/Pods/../Flutter/Flutter.framework/Headers/Flutter.h:54:
In file included from .../Documents/Flutter/patient_medical_record/ios/Pods/../Flutter/Flutter.framework/Headers/FlutterAppDelegate.h:11:
.../Documents/Flutter/patient_medical_record/ios/Pods/../Flutter/Flutter.framework/Headers/FlutterPlugin.h:395:11: note: 'FlutterPluginRegistry' declared here
#protocol FlutterPluginRegistry
^
3 errors generated.
In file included from .../.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/ios/Classes/FLTPathProviderPlugin.m:5:
.../.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/ios/Classes/FLTPathProviderPlugin.h:5:9: fatal error: could not build module 'Flutter'
#import
~~~~~~~^
4 errors generated.
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Well this is a bummer because I can't find a clean solution, but for now I did fix it with the following:
Create a new flutter project
Copied over the lib files
Copied over other setup in random places (i.e. google services, android changes)
Copied over pubspec.yaml and ran packages get
It now works again. Clearly something went wrong in the Flutter-managed files that I don't understand. If someone else can think of a better solution to effectively reset the project, please share.

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 .