Incomplete import in the generated_plugin_registrant.dart - flutter

I have a plugin created using the federated approach. The problem is that the generated_plugin_registrant.dart contains an incomplete import which is pointing to the app-facing package but leaves out the dart file name and this causes an error.
import 'package:my_plugin/'; // PROBLEMATIC LINE
import 'package:my_plugin_web/my_plugin_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
.registerWith(registrar); // PROBLEMATIC LINE
MyPluginWeb.registerWith(registrar);
registrar.registerMessageHandler();
}
This code is in the default example app for a plugin with an unchanged default pubspec.yaml.
Here's the pubspec.yaml for the app-facing "my_plugin" package:
name: my_plugin
description: A new flutter plugin project.
version: 0.0.1
author:
homepage:
environment:
sdk: '>=2.12.0 <3.0.0'
flutter: '>=1.20.0'
dependencies:
flutter:
sdk: flutter
my_plugin_platform_interface:
path: ../my_plugin_platform_interface
my_plugin_web:
path: ../my_plugin_web
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
plugin:
platforms:
android:
package: com.example.my_plugin
pluginClass: MyPlugin
ios:
pluginClass: MyPlugin
web:
defaultPackage:
path: my_plugin_web
I've tried all the usual commands like flutter clean and recreating the project but to no avail.

Under your web definition (which Google wants in a separate project you have to specify it as
web:
pluginClass: The class name of your web class here
fileName: The file name of the file that holds your web class here
I had it has just "file" and yours is "path" which will cause this.

The issue is that plugin support for the web was not generated for a specific package or packages.
Try creating an analysis_options.dart and add these lines
analyzer:
exclude: [lib/generated_plugin_registrant.dart]
then configure your vscode/.settings.json with these lines
"dart.analysisExcludedFolders":["./yourApp/lib/generated_plugin_registrant.dart" ]

Just find the answer, basically you need to use default_package to specify your are using the integrated plugin. More here

Related

package is forbidden but only when it's imported

Here's an error I'm getting when trying to save the pubspec.yaml (which automatically runs flutter pub get) (I changed the names of the packages):
Running "flutter pub get" in ravencoin_front...
Because every version of package_b from path depends on
package_c any which is forbidden, package_b from path is
forbidden. So, because package_a depends on package_b from
path, version solving failed. pub get failed (server unavailable) --
attempting retry 1 in 1 seconds...
So the question is, why is package_c forbidden? Here's what package_c looks like:
pubspec.yaml:
name: package_c
version: 1.0.0
description: Serverpod client for communication to the consent server and database.
homepage: https://github.com/.../package_c
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
serverpod_client: ^0.9.8
/lib/package_c.dart
library package_c;
export 'package:package_c/src/protocol/protocol.dart';
export 'package:serverpod_client/serverpod_client.dart';
Finally here's protocol.dart:
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
/* To generate run: "serverpod generate" */
// ignore_for_file: public_member_api_docs
// ignore_for_file: unnecessary_import
library protocol;
// ignore: unused_import
import 'dart:typed_data';
import 'package:serverpod_client/serverpod_client.dart';
import 'consent_class.dart';
import 'consent_document_class.dart';
export 'consent_class.dart';
export 'consent_document_class.dart';
export 'client.dart';
class Protocol extends SerializationManager {
static final Protocol instance = Protocol();
final Map<String, constructor> _constructors = {};
#override
Map<String, constructor> get constructors => _constructors;
Protocol() {
constructors['Consent'] = (Map<String, dynamic> serialization) =>
Consent.fromSerialization(serialization);
constructors['ConsentDocument'] = (Map<String, dynamic> serialization) =>
ConsentDocument.fromSerialization(serialization);
}
}
There are no errors, not sure why this package is seen as "forbidden."
Now package_b also requires other pacakges and overrides their paths, and they work just fine. so at first I thought it doesn't like the "nested paths" part of this situation, but that's not it, otherwise it would complain about the others too.
I also wondered, maybe the issue is that it has two "library" listed in the files. but I don't think that's it because if I remove the library package_c; it has the same problem.
Maybe it's as simple as this package_c not being correctly setup as a package, but I think it is, I looked up the requirements and it seems to fit from what I found.
Just for good measure let me include some of package_b pubspect.yaml:
name: package_b
description: Ravencoin wallet backend library
version: 1.0.0
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
...
package_d: ^4.0.1
...
package_c: ^1.0.0
dependency_overrides:
# causes error!
package_c:
path: ../../package_c
# works fine!
package_d:
path: ../../package_d
...
Now, Here's the really weird part. remember, package_a imports pacakge_b which imports package_c. Well, package_b works just fine, dart pub get works great. but when I run flutter pub get in package_a, the error at the top occurs. the weird thing is only package_a complains about package_c, package_b is fine with package_c... what?
I guess I should include part of the pubspec.yaml for package_a too, this is the one that causes the error:
name: package_a
description: Ravencoin wallet frontend
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+0
environment:
sdk: '>=2.14.0 <3.0.0'
dependencies:
...
flutter:
sdk: flutter
package_b: ^1.0.0
...
dependency_overrides:
package_b:
path: ../package_b
...
...

Flutter: Call static code into pubspec.yaml for versioning dependencies

For example, I have a dependecies_version.dart file. And this is the code for that file.
class DependeciesVersion {
static const http = "^3.2.1";
static const bloc = "^6.0.5";
}
And on the pubspec.yaml file is like this.
dependencies:
flutter:
sdk: flutter
http: DependeciesVersion.http
flutter_bloc: DependeciesVersion.bloc
It's possible?
Why I need this approach? Because I have each module with implemented same dependencies. So I just focus on dependecies_version.dart file for updating the version of dependencies instead of checking all pubspec.yaml file on each module.
In Native we have kotlin-dsl for handle this if implementation modular concept
I think for now not supported that way, but I fix it by creating a module/package only for handling dependencies.
So if your feature module needs those dependencies, just add it in pubspec.yaml in your feature modules.
dependencies:
flutter:
sdk: flutter
dependencies:
path: ../dependencies
Here is the example: https://github.com/rrifafauzikomara/NewsApp

Flutter | Dart : Target of URI does not exist

I am making my first Application to build an Android App with Flutter.
I am using Android Studio as IDE.
The problem is when I import the http package:
import 'package:http/http.dart' as http;
I get an error :
error: Target of URI doesn't exist: 'package:http/http.dart'.
(uri_does_not_exist at [flutter_crypto] lib\home_page.dart:3)
That's my code :
Future<List> getCurrencies() async{
String cryptoUrl = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
http.Response response = await http.get(cryptoUrl);
return JSON.decode(response.body);
}
Thanks,
You need to add the HTTP dependency to pubspec.yaml as per below.
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
http: ^0.12.0
With the dependency added you then need to run the following command to update/install required packages:
flutter packages upgrade
Hope this helps
Make sure you have added the dependency to pubspec.yaml
dependencies:
http: ^0.12.0
You will also need to:
flutter packages get
For any upcoming problem with importing packages from dart please go to official Dart website packages and search for needed package and you will find solution up there.
for your issue go to:
https://pub.dartlang.org/packages/http
Installing tap https://pub.dartlang.org/packages/http#-installing-tab-
follow guide steps:
In pubspec.yaml file:# dependencies
dependencies:
http: ^0.12.0
flutter:
(NB: please make sure that http & flutter or any other attribute inside dependencies are aligned as above and they are at same line)
In terminal run below command:
$flutter packages get
run: dart pub --trace get --no-precompile in android srudio Terminal

How to import intl library in Flutter?

I am new in Flutter. When I import the library: import 'package:intl/intl.dart'; , it says that the target of URI doesn't exist:package:intl/intl.dart;
When you import any package, example:
import 'package:intl/intl.dart';
You need to also add the package inside the pubspec.yaml file under the dependencies field example:
dependencies:
intl: ^0.15.7
Then from the terminal you can execute the following command:
flutter packages get
or
From Android Studio/IntelliJ:
Click Packages Get in the action ribbon at the top of pubspec.yaml
more info here:
https://flutter.io/using-packages/
Just to double check, you did import intl: ^0.15.7 into pubspec.yaml; triple check that it has four spaces in front of it (no more and no less); and you ran packages get?
Also, put your focus on the tab for main.dart and hit the green arrow to run it. Sometimes you will then see a popup bar at the top of the screen that tells you pubspec.yaml has changed and you need to run it again from that link in order for it to take. (I've seen that in IntelliJ)
Also, if it's showing red lines under publspec.yaml in the project window but everything is working, that's a bug in the analysis. Ignore it but yes, they do know about it and are working on it. It's often there because, for some reason, pubspec.yaml says your assets directory doesn't exist even though you can access the assets without any problem.
Let IDE do this for you :
flutter pub add intl
After running above command, It will resolve the dependency with the latest version available.
OR
Manual Process
1) Add package in pubspec.yaml file under dependencies field :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
intl: ^0.17.0 // Add this line
2) Execute the following command in terminal :
flutter packages get
3) Import package in your dart file :
import 'package:intl/intl.dart';
if you are facing errors while installing
it coming because of your old version of SDK.
Just fall back to the intl version back by some points in your pubs
intl: ^0.17.0 ---> intl: ^0.16.1 or any other older version like intl: ^0.15.1 etc.
Sometimes its the version of packages which after update not compatible with your old sdk

Unable to find module for angular - bootstrap/modules.template.dart

I have a problem with transpiling Angular Dart application to javascript.
I got following error messages:
*Loading source assets...
Loading dart_to_js_script_rewriter transformers...
Building testapp...
Building dartdevc modules...
Unable to find module for angular|lib/src/bootstrap/modules.template.dart
Unable to find module for angular|lib/src/bootstrap/modules.template.dart
Build failed.*
Some highlights:
Application works fine with build_runner
I use dart SDK 2.0.0-dev.32.0
I tested and get same results on Win10 and Linux Ubuntu 17
I tested with dartdevc with and without
Below you can see my pubspec.yaml It could be there is an issue what I can not see.
name: testapp
description: A web app that uses AngularDart Components
version: 0.0.1
environment:
sdk: '>=2.0.0-dev.1.2 <2.0.0'
dependencies:
angular: "5.0.0-alpha+6"
angular_components: "0.9.0-alpha+6"
http: "^0.11.3+16"
stream_transform: "^0.0.10"
angular_router: "2.0.0-alpha+6"
js: "^0.6.1"
intl_translation: "^0.16.1"
intl: "^0.15.2"
dependency_overrides:
analyzer: ^0.31.0-alpha.1
dev_dependencies:
webdriver: "^2.0.0-beta"
browser: "^0.10.0+2"
dart_to_js_script_rewriter: "^1.0.3"
test: "^0.12.30+2"
build_runner: "^0.7.9+2"
build_web_compilers: "^0.3.0"
sass_builder: ^1.1.2 # update for the latest version
transformers:
- $dart2js:
commandLineOptions: [--trust-type-annotations, --trust-primitives, --show-package-warnings, --dump-info, --fast-startup]
- dart_to_js_script_rewriter
For now I have no clue how to debug the problem. Any leads will be very welcome.
Thanks!