Using: dart 2.0.0
How do you create components for AngularDart?
I have with no luck, looked at https://github.com/dart-lang/angular_components
I have done the following steps:
stagehand package-simple
added export to dart file with library <packageName>;
referenced the package in pubspec.yaml
You must have a dependency on build_runner in pubspec.yaml.
dev_dependencies:
build_runner: >=0.8.10 <2.0.0
You must have a dependency on build_web_compilers in pubspec.yaml.
dev_dependencies:
build_web_compilers: >=0.3.6 <0.5.0
Please check the following imports:
`import 'package:<...>template.dart''
I have tried to build the package with:
webdev build
webdev could not run for this project.
You must have a dependency on `build_runner` in `pubspec.yaml`.
# pubspec.yaml
dev_dependencies:
build_runner: >=0.8.10 <2.0.0
You must have a dependency on `build_web_compilers` in `pubspec.yaml`.
# pubspec.yaml
dev_dependencies:
build_web_compilers: >=0.3.6 <0.5.0
Note: Using just a simple class, it works - but not with web components:
This works:
class Awesome {
bool get isAwesome => true;
}
This do not:
import 'package:angular/angular.dart';
#Component(
selector: 'my-card',
templateUrl: 'my_card.html',
styleUrls: ['my_card.css'],
directives: [coreDirectives],
// pipes: [commonPipes],
)
class MyCard {
var cardstring = 'My Card - string';
}
When using it in anyway:
<my-card></my-card>
Create a Dart project with pubspec.yaml (name, SDK constraints, Angular dependency).
Create a component file in lib/my_component.dart and lib/my_component.html.
That's it.
Alternatively you can put the component in lib/src/my_component.* with a file like lib/my_components.dart
export 'src/my_component.dart';
In you application project where you want to use the component package, add a dependency to your component package.
dependencies:
angular: ^5.0.0
my_components: ^0.1.0 # requires the package to be published to pub.dartlang.ort
# alternatively (without publishing
my_components:
path: ../my_components
# or if checked in to GitHub
my_components:
git: git://github.com/myaccount/my_components.git
See also https://www.dartlang.org/tools/pub/dependencies
Then you use the component by importing it
import 'package:my_components/my_components.dart';
#Component(
selector: ....
directives: [MyComponent],
...
)
class AppComponent {}
and add it to AppComponent (or any other components) HTML as
<my-component></my-component>
Related
I have a flutter package flutter_opencc_ffi_web, which contains some JS files. This package is transitively included in another project of mine. When I build a non-web bundle, I'd like to exclude the JS assets(about 1Mb). How can I achieve that?
I've tried the build_config, but don't know how to exclude package assets. The following config doesn't work.
build.yaml
targets:
$default:
sources:
exclude:
- assets/opencc/**
- assets/packages/flutter_opencc_ffi_web/assets/opencc/**
dependencies:
flutter_opencc_ffi_web:
exclude:
- assets/opencc/**
After upgrading to Flutter 3.0 I started to get a lot of depend_on_referenced_packages lint issues when running flutter analyze. If I remove the reported imports the compilation breaks. Most of the issues are with package:collection/collection.dart which provides extension methods.
Currently the best I could find is to suppress this lint for the affected files by adding // ignore_for_file: depend_on_referenced_packages. However I like this lint (and in general I'd want to keep as much lints enabled as possible), so is there a way to suppress the lint only for a just a specific import and not for all imports in the file?
Relevant sections of pubspec.yaml:
...
environment:
sdk: ">=2.17.1 <3.0.0"
flutter: ">=3.0.1"
...
dev_dependencies:
flutter_lints: ^2.0.1
Running:
$ flutter analyze
...
info • Depend on referenced packages • lib/preferences/palette_spec.dart:3:8 • depend_on_referenced_packages
info • Depend on referenced packages • lib/ui/parts/circular_menu.dart:5:8 • depend_on_referenced_packages
...
Source code examples:
database_utils.dart (firstWhereOrNull is from collection.dart):
...
import 'package:collection/collection.dart';
...
Activity? _getActivityById(int id) {
return activities.firstWhereOrNull((element) => element.id == id);
}
...
Record? _getRecordById(int id) {
return records.firstWhereOrNull((element) => element.id == id);
}
palette_spec.dart (forEachIndexed is from collection.dart):
...
import 'package:collection/collection.dart';
...
paletteStr.split(",").forEachIndexed((index, colorStr) {
...
});
circular_menu.dart:
...
import 'package:vector_math/vector_math.dart' as vector;
...
final angle = vector.radians(90.0 / (widget.children.length - 1) * index + angleFix);
Note: the root cause is that collection is brought in as a transitive dependency.
Originally I misunderstood the lint. Explanation to Petr's solution: when he says "lint is reported if you depend on a transitive dependency" it means that somewhere in my code I have an import which imports stuff from that dependency. But at the time of the lint that dependency is only transitive, not direct. Therefore if I'd decide - for whatever reason - to not depend on the package which brings that in then suddenly I'd have an error out o the blue for that import. The lint tries to make that dependency graph more direct.
This lint is reported if you depend on a transitive dependency. Do you have in your pubspec.yaml defined collection?
dependencies:
collection: ^1.16.0
I had same issue but after defining dependency, lint issue is gone.
I have customised a Flutter package and therefore it's outside of my lib folder.
Structure:
project_name
lib
file.dart
package
package_file.dart
I want to import file.dart into package_file.dart. How can I achieve this?
Tried import 'package:project_name/lib/file.dart' but it says URI not exist.
You should have pubspec.yaml in your package module and declare your project root file packages yaml's dependencies like this :
dependencies:
ROOT_PROJECT_NAME:
path: ../../ROOT_PROJECT_NAME
I have some code that I need to share across test targets, while I'm using the Swift Package Manager. To do this, I have a .testTarget that I also name as a dependency in another .testTarget.
Here is a simple example:
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ExampleLib",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ExampleLib",
targets: ["ExampleLib"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ExampleLib",
dependencies: []),
.testTarget(
name: "Common",
dependencies: ["ExampleLib"]),
.testTarget(
name: "ExampleLibTests",
dependencies: ["Common"]),
]
)
If I try to build this package in Xcode, I get the following error:
Unable to resolve build file: XCBCore.BuildFile (The workspace has a reference to a missing target with GUID 'PACKAGE-TARGET:Common')
However, if I build from the command line (swift build) or test from the command line (swift test), I get success.
I'm using Xcode 12 beta 6, but have also tried Xcode 11.5 (with a change to the Package.swift header) and get the same results.
Here is the complete Swift package example:
https://www.dropbox.com/s/h6ypvbfonnb2zyk/ExampleLib.zip?dl=0
I really would like to use this in Xcode to build for iOS. Thoughts?
I faced the same issue and solved it by defining a Target (not Test Target) instead for Common.
My Package.swift file:
// ...
.target(name: "Common", dependencies: ["App"], path: "Tests/Common"),
.testTarget(name: "AppTests", dependencies: ["App", "Common"]),
.testTarget(name: "IntegrationTests", dependencies: ["App", "Common"])
// ...
I am following this article
How to Create a Chat App with Backendless SDK for Flutter
import 'package:flutter/material.dart';
import 'package:backendless_sdk/backendless_sdk.dart';
import 'package:backendless_sdk/src/modules/modules.dart';
There is a error:
"Target of URI doesn't exist: 'package:backendless_sdk/src/modules/modules.dart'."
The modules.dart import is required for Backendless.Messaging, but without the import there is an error:
The getter 'Messaging' isn't defined for the type 'Backendless'.
void initListeners() async {
Channel channel = await Backendless.Messaging.subscribe("myChannel");
channel.addMessageListener(onMessageReceived);
}
pub spec.yaml
dependencies:
flutter:
sdk: flutter
backendless_sdk: ^1.1.8
How can I import the Messaging module?
You should change from:
await Backendless.Messaging.subscribe
in to:
await Backendless.messaging.subscribe
^
|
small "m" here
Versions
I checked backendless_sdk: ^0.0.2 (from tutorial) and backendless_sdk: ^1.1.8 (newest one), and in both cases this field was named messaging (lowercase).
Class Backendless
backendless_sdk-1.1.8/lib/src/backendless.dart:
It look like you are missing the installation step.
From the terminal: Run flutter pub get.
OR
From Android Studio/IntelliJ: Click Packages get in the action ribbon
at the top of pubspec.yaml.
From VS Code: Click Get Packages located
in right side of the action ribbon at the top of pubspec.yaml.
I do not see any references to modules.dart in the article you mentioned. You need to import backendless_sdk and also include the socket.io dependency:
dependencies {
implementation ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
}