Why the app produced by flutter build web sometimes doesn't work? - flutter

I have 2 issues that only appear when executing flutter build web.
Sometimes flutter build web fails complaining (wrongly) about types that were not compatible (see below).
Sometimes the build process finishes but then the web app doesn't work: doesn't display anything and there are no messages in the console.
The error I mention is something like this:
% flutter build web
Target dart2js failed: Exception: lib/main.dart:24:31:
Error: A value of type 'ApiUsersRepository' can't be assigned to a variable of type 'UsersRepository'.
- 'ApiUsersRepository' is from 'package:my_app/api_users_repo.dart' ('lib/api_users_repo.dart').
- 'UsersRepository' is from 'lib/users_repo.dart'.
final UsersRepository usersRepository = ApiUsersRepository();
^
Error: Compilation failed.
The app is working in iOS and web when developing.

The solution
I changed all imports of my files like:
import 'package:my_app/users_repo.dart';
To:
import 'users_repo.dart';
More Details
Investigating the error about types, I found this issue, where the important part is this comment: after changing every import to relative format it resolves my problem.
So I did that, and it solved the 2 issues, the compilation error, and the runtime error.

for me I had to remove a package that was corrupted. c:\src\flutter.pub-cache\hosted\pub.dartlang.org\localstorage-4.0.0+1 Apparently, a file had become corrupted by me invertly. I removed the package and did a flutter pub get then recompiled and it worked.

Related

Facing a problem to set up the emulator in flutter

I have the following problem.....
Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
int _counter = 0;dsggfsgfh;
^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
I'm a beginner with Flutter. How can I solve this problem?
Your code has junk words or sentences, check your line ended with dsggfsgfh; which might be added unfortunately. Just remove it this will work.
It's possible that it's a compatibility issue between flutter framework and engine. You can try and:
Upgrade flutter to the latest version
Create a new project
Copy the code from the old project in steps
If you have plugins from the old project, add them one by one as you run the emulator
(It's possible that a certain version of a plugin has a compatibility issue with flutter)

Flutter Redux Navigation library import error

I have been developing application and one of the libraries I have used was Flutter Redux Navigation. Everything was working fine, until recently, when I started getting following error
../../lib/src/navigation_middleware.dart:3:1: Error: 'NavigationDestination' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_redux_navigation/src/navigation_destination.dart'.
import 'package:flutter_redux_navigation/src/navigation_destination.dart';
^^^^^^^^^^^^^^^^^^^^^
../../lib/src/navigation_middleware.dart:35:26: Error: 'NavigationDestination' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_redux_navigation/src/navigation_destination.dart'.
this._setState(NavigationDestination(
^^^^^^^^^^^^^^^^^^^^^
../../lib/src/navigation_middleware.dart:55:26: Error: 'NavigationDestination' is imported from both 'package:flutter/src/material/navigation_bar.dart' and 'package:flutter_redux_navigation/src/navigation_destination.dart'.
this._setState(NavigationDestination(
I even tried to copy example project from their git, and got exactly same error. This is something in library, or perhaps some settings of my IDE? Please let me know if anyone encountered this error.
The problem was that I have upgraded Flutter version from 2.5.1 to 2.8.0. The newest Flutter version contains upgraded Material library, which contains the method called NavigationDestination. Thus both, the library and Material design have the same name of the class, of course, resulting in error.

Groovy:General error during semantic analysis: java.lang.NoSuchMethodError:

Imported the gradle project from the "complete" folder and received the following error:
Groovy:General error during semantic analysis:
java.lang.NoSuchMethodError: 'org.codehaus.groovy.ast.expr.Expression org.codehaus.groovy.ast.tools.GeneralUtils.propX(org.codehaus.groovy.ast.expr.Expression, java.lang.String)'
I am using the latest version of Eclipse, 2020-12, with groovy tools installed.
From grails guide
https://guides.grails.org/gorm-without-grails/guide/index.html
Downloaded code sample from github
https://github.com/grails-guides/gorm-without-grails.git
It seems likely to be a version mismatch, but I cannot determine how to correct this problem.
I have tried to delete the offending file, src/main/groovy/demo/domain/Manufacturer.groovy, and the error appears on the file in this package on line 1.
The error does not appear in any other package. I have done the usual internet searches for resolutions that apply, but have thus far been unable to find a suitable solution. I am hopeful for a suggestion?
I think this error comes from an AST transform that references the older signature of GeneralUtils#propX. This method used to return Expression and was changed to return PropertyExpression.
The bridge method for binary compatibility was missing in groovy-eclipse. https://github.com/groovy/groovy-eclipse/commit/f6f448675d95f858b4ec65b6fc8e55f27ccaaa94

i'm having this error with the flutter version for web each time i try to test it. But it works fine on mobile

Everything works fine and App is already in the play store but when i try to test for a web version it produces below error just for this particular App.
I want to know what is exactly wrong
lib/main.dart:15:8: Error: Error when reading
'lib/generated_plugin_registrant.dart': The system cannot find the
file specified.
import 'package:[NameOfApp goes
here]/generated_plugin_registrant.dart';
^ lib/main.dart:16:8: Error: Error when reading 'lib/generated_plugin_registrant.dart': The system cannot find the
file specified.
org-dartlang-app:/web_entrypoint.dart:11:3: Error: Method not found: 'registerPlugins'.
registerPlugins(webPluginRegistry);
^^^^^^^^^^^^^^^
Failed to compile application.

Migrating to Dart 2 I get a "check imports error" that means that some templates have not been generated

I'm trying to migrate to Dart 2, I have a lot of packages and up to now I could do my job with not so much problems.
Now I'm getting a strange error bot with DDC and dart2js:
[SEVERE] 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).
Please check the following imports:
`import 'package:ledger_web/src/ui/components/main_selection_bar.template.dart';` from ledger_web|lib/src/ui/components/service/main_selection_bar_service.dart at 7:1
`import 'package:ledger_web/src/ui/components/main_selection_bar.template.dart';` from ledger_web|lib/src/ui/components/service/main_selection_bar_service.template.dart at 11:1
... and more
It is correct to signal that there is not the import (MainSelectionBar is an angular component), because the template has not been generated.
Now the problem is, why the template is not there?
I checked the .dart_tool/build/generated directory but the template has not been created.
I have a similar package with a similar component that works fine, so I cannot figure out what's happened.
Is there a place where there is a more detailed error list?
Interestingly enough, there is also a case in which the template exists, but it is listed like if it was not found....
Any hint?
Most likely this is related to a build failure when generating the template, which is not being properly reported on subsequent builds. This pull request should help that https://github.com/dart-lang/build/pull/1834/, but you can also try running pub run build_runner clean and then doing a new build to get the original error back.