My Dart app project structure:
myapp/
pubspec.yaml
pubspec.lock
asset/
...assets
build/
packages/
web/
lookups/
AjaxLookups.dart
requests/
RESTClient.dart
AjaxRESTClient.dart
The AjaxLookups file:
library myapp;
abstract class AjaxLookups {
static final String BASE_URL = "/myapp";
static final String DO_S0METHING_SERVICE_URL = BASE_URL + "/doSomething";
}
The RESTClient file:
library myapp;
typedef void Callback(String json);
abstract class RESTClient {
void get(String url, Callback onFail, Callback onSuccess);
void post(String url, String dataJSON, Callback onFail, Callback onSuccess);
}
The AjaxRESTClient file:
library myapp;
import "RESTClient.dart";
import "../lookups/AjaxLookups.dart";
import "dart:html";
import "dart:convert" show JSON;
class AjaxRESTClient implements RESTClient, AjaxLookups {
// ...
}
Above, the import statement for AjaxLookups is causing a compiler error:
Target of URI does not exist: '../request/AjaxLookups.dart'
Why am I getting this? Why can't Dart find ../request/AjaxLookups.dart? What do I need to do to fix it?
It looks like the file AjaxLookups.dart is in the lookups folder, so your import should be:
import "../lookups/AjaxLookups.dart";
I figured it out. I was declaring a new myapp library inside each source file. Instead I added a main/driver Dart file, declared a library in it called myapp, and then changed all the other source files to be part of myapp;.
Related
I'm using Injectable and I have two classes. WebImageDownloader and MobileImageDownloader. Both are implementing ImageDownloader which is an abstract class. I'm registering web and mobile image downloaders as ImageDownloader with Injectable, one registered under web, one under mobile environment.
But since WebImageDownloader has dart:js and dart:html imports, I can't run my code. Because these libraries are not found.
I see on some answers that people do conditional imports between dart:io and dart:html but it doesn't work for me.
Also, the question is under issues for Injectable.
import 'MobileFileDownloader.dart'
if (dart.library.html) 'WebFileDownloadService.dart';
abstract class NativeFileDownloader {
void downloadFile(List<int> bytes, String downloadName);
factory NativeFileDownloader() =>getDownloader();
}
import 'NativeFileDownloader.dart';
class WebFileDownloadService implements NativeFileDownloader{
void downloadFile(List<int> bytes, String downloadName) {
// Encode our file in base64
final _base64 = base64Encode(bytes);
// Create the link with the file
final anchor = AnchorElement(href: 'data:application/octet-stream;base64,$_base64')
..target = 'blank'
..setAttribute('download', downloadName);
// add the name
//anchor.download = downloadName;
// trigger download
document.body?.append(anchor);
anchor.click();
anchor.remove();
return;
}
}
NativeFileDownloader getDownloader()=>WebFileDownloadService();
import 'package:flovo/Services/FileDownloadService/Native/NativeFileDownloader.dart';
class MobileFileDownloader implements NativeFileDownloader{
#override
void downloadFile(List<int> bytes, String downloadName) {
}
}
NativeFileDownloader getDownloader()=>MobileFileDownloader();
use => NativeFileDownloader().downloadFile(list, 'image.jpeg');
How can I use the websocket package with dart web? I have the following code
import 'package:projectname/data/chat/chat_message.dart';
import 'package:projectname/data/chat/chat_provider.dart';
import 'package:web_socket_channel/io.dart';
import '../path.dart';
class MockChatProvider implements ChatProvider {
#override
IOWebSocketChannel connect() {
return IOWebSocketChannel.connect(Uri.parse(Path.joinChat));
}
#override
sendChatMessage(IOWebSocketChannel channel, ChatMessage message) {
channel.sink.add(message.toJson());
}
}
But when I try to connect I get the following error
Unsupported operation: Platform._version
The package does say it supports web. What am I doing wrong?
Just use the package package:web_socket_channel/web_socket_channel.dart
TLDR;
I think you should use this...
import 'package:web_socket_channel/web_socket_channel.dart';
...instead of...
import 'package:web_socket_channel/io.dart';
and use it as
WebSocketChannel connect() {
...
return WebSocketChannel.connect(Uri.parse(Path.joinChat));
...
sendChatMessage(WebSocketChannel channel, ChatMessage message) {
Note: I have not tried and tested it!
I think the problem is that you found the right package, but you're using directly IOWebSocketChannel. That only works on places where dart:io is available. There's another class in that package, HtmlWebSocketChannel that only works on the web.
I think the issue is that you are importing package:web_socket_channel/io.dart for web and you should instead import package:web_socket_channel/web_socket_channel.dart.
Related GitHub issue on package's repo: https://github.com/dart-lang/web_socket_channel/issues/159
I am trying to create a dart package and use it in my few flutter projects. The package is not public it’s a private package. I am trying to understand how to create a package with working on an example. The documentation wasn’t so difficult, but it confuses me, because I am new to this type project.
So, I create private dart package project. My package name is socket_conn. The socket_conn.dart has single export line as export 'src/socket_conn_base.dart'; My socket_conn_base.dart has 1 class and 1 Future method.
My intention is to import this package to my flutter app, send data to EncrptedSocketCommunication and wait EncrptedSocketCommunication returns data from getQuery. It didn’t work.
I am not sure if I am doing right but calling EncrptedSocketCommunication how do I fire getQuery method, so it goes another class under my src folder (getQueryA100) and gets the data. The getQueryA100 has a working and tested code. But when I import this package to my flutter app
İt doesn’t call Future>> getQuery.
My question is how to call dart package method from Flutter app?
import 'csbins_socket/getQueryA100.dart';
List<List<dynamic>> _returnData;
class EncrptedSocketCommunication {
String connectionText;
String queryText;
String parameterText;
EncrptedSocketCommunication(
this.connectionText,
this.queryText,
this.parameterText
);
Future<List<List<dynamic>>> getQuery(String connectionText, String queryText, String parameterText) async {
switch (queryText){
case "QA100": {
_returnData = await getQueryA100(queryText, parameterText);
return _returnData;
}
break;
}
}
}
I'm upgrading an Apache FOP 1.0 project to Apache FOP 2.1. In this project, all necessary files are packaged within the jar file.
I've added the new FopFactoryBuilder to generate a FopFactory
FopFactoryBuilder builder = new FopFactoryBuilder(new File(".").toURI());
builder = builder.setConfiguration(config);
fopFactory = builder.build();
but all my resouces are loaded from the relative path on my file system, not from the jar. How can I set the baseURI to the jar's classpath?
Thanks
We also used FOP 2.1 and want to achieve, that images inside jars-classpath will be found. Our tested and used solution is the following:
Create your own ResourceResolver
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.xmlgraphics.io.Resource;
import org.apache.xmlgraphics.io.ResourceResolver;
public class ClasspathResolverURIAdapter implements ResourceResolver {
private final ResourceResolver wrapped;
public ClasspathResolverURIAdapter() {
this.wrapped = ResourceResolverFactory.createDefaultResourceResolver();
}
#Override
public Resource getResource(URI uri) throws IOException {
if (uri.getScheme().equals("classpath")) {
URL url = getClass().getClassLoader().getResource(uri.getSchemeSpecificPart());
return new Resource(url.openStream());
} else {
return wrapped.getResource(uri);
}
}
#Override
public OutputStream getOutputStream(URI uri) throws IOException {
return wrapped.getOutputStream(uri);
}
}
Create the FOPBuilderFactory with your Resolver
FopFactoryBuilder fopBuilder = new FopFactoryBuilder(new File(".").toURI(), new ClasspathResolverURIAdapter());
Finally address your image
<fo:external-graphic src="classpath:com/mypackage/image.jpg" />
Because you use our own Resolver it is possible to do every lookup which you want.
By specifying the URL as a classpath URL like:
<fo:external-graphic src="classpath:fop/images/myimage.jpg"/>
In this example the file is a resource in the resource-package fop.images but the actual file gets later packed to some entirely different place inside the JAR, which is - however - part of the classpath, so the lookup as above works.
I just finished configuring hybris and tried to set up the eclipse project. As per guidelines in the wiki.hybris, I imported all the extensions into the eclipse project. When I try into build and clean, I get more than 3000 compiler errors. One of the errors is the class AbstractTrackingEvent cannot be resolved to a type. I looked for the particular class in the project folder. I could not find the folder events under de.hybris.eventtracking.model, which is the cause of the issue.
Am I missing anything while importing the project? There are many such type of issues in my eclipse project. Please let me know how to fix it. I have attached the screenshot for reference.
Note: I am using hybris-commerce-suite 5.7.0.8
As requested, I am adding the source code.
package de.hybris.eventtracking.services.populators;
import de.hybris.eventtracking.model.events.AbstractTrackingEvent;
import de.hybris.eventtracking.services.constants.TrackingEventJsonFields;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* #author stevo.slavic
*
*/
public abstract class AbstractTrackingEventGenericPopulator implements
GenericPopulator<Map<String, Object>, AbstractTrackingEvent>
{
private final ObjectMapper mapper;
public AbstractTrackingEventGenericPopulator(final ObjectMapper mapper)
{
this.mapper = mapper;
}
public ObjectMapper getMapper()
{
return mapper;
}
protected Map<String, Object> getPageScopedCvar(final Map<String, Object> trackingEventData)
{
final String cvar = (String) trackingEventData.get(TrackingEventJsonFields.COMMON_CVAR_PAGE.getKey());
Map<String, Object> customVariablesPageScoped = null;
if (StringUtils.isNotBlank(cvar))
{
try
{
customVariablesPageScoped = getMapper().readValue(cvar, Map.class);
}
catch (final IOException e)
{
throw new ConversionException("Error extracting custom page scoped variables from: " + cvar, e);
}
}
return customVariablesPageScoped;
}
}
"As per guidelines in the wiki.hybris, I imported all the extensions into the eclipse project."
I don't think the guidelines tell you this. Basically, you want the projects loaded to be the same as those defined in your localextensions.xml and their dependencies. The reason you can't see those is they are not built.
Ensure you have run 'ant build' successfully, refresh the platform project, remove any extensions from your workspace that are not needed for your project, and clean and build in eclipse.
Make sure you have provided the project dependencies in each project by checking their individual extensioninfo.xml files as shown in below image.
Also sometimes dependent libraries are not imported properly check for those too.