I have integrated the Flutter Health package in my Flutter App and it works fine on android, although the page throws an error on iOS(P.S. The HealthKit Capability has been added). The UI Does not load and throws the following error
The code that the error points to is as follows,
dynamic stepCount() {
double steps = 0.0;
if (_countDataList.isNotEmpty)
_countDataList.forEach((count) => steps += count.toJson()['value']);
return steps;
}
double caloryCount() {
double calories = 0;
if (_caloriesDataList.isNotEmpty)
_caloriesDataList.forEach((cal) => calories += cal.toJson()['value']);
return calories;
}
The solution to this is to pass a double Zero(0.0) as a value for the count variable
How can I make possible that the app will load all of the images from the specific folder and then put in array and choose one image randomly? When chose one then pass to the fronted to show the image. How to do that too?
I am C# developer but not long time ago I found ElectronJS and this framework does everything easier so therefore I am moving to this framework.
I did in C# programming this way:
// basic settings.
var ext = new List<string> { ".jpg", ".gif", ".png" };
// we use same directory where program is.
string targetDirectory = Directory.GetCurrentDirectory() + "\\assets\\" + "images\\" + "animals\\";
// Here we create our list of files
// New list
// Use GetFiles to getfilenames
// Filter unwanted stuff away (like our program)
if (Directory.Exists(targetDirectory))
{
Files = new List<string>
(Directory.GetFiles(targetDirectory, "*.*", SearchOption.TopDirectoryOnly)
.Where(s => ext.Any(es => s.EndsWith(es))));
// Show first picture so we dont need wait 3 secs.
ChangePicture();
}
else
{
panel5.BackgroundImage = new Bitmap(Resources.doggy);
}
I don't know how to do in ElectronJS.
Thank you in advance the answers.
Alright. I found the solution.
However I don't understand the people who are giving negative reputation for the opened question. If they are giving negative reputation then they could explain why.
Well anyway, I did fix this issue with this way:
I created images.js file and added this:
var fs = require('fs');
function getRandImage() {
var files = fs.readdirSync('./assets/images/animals/')
/* now files is an Array of the name of the files in the folder and you can pick a random name inside of that array */
let chosenFile = files[Math.floor(Math.random() * files.length)]
console.log('../assets/images/animals/' + chosenFile);
return '../assets/images/animals/' + chosenFile;
}
module.exports = { getRandImage }
I used console to see if the value is correct, otherwise others can delete that part.
Sending the data to the renderer process:
const { getRandImage } = require('./images');
child.webContents.send('random-image', getRandImage());
I did put in the preload.js file the following (I used the starter pack electronjs github to start with something):
var { ipcRenderer } = require('electron');
ipcRenderer.on('random-image', function (event, store) {
document.getElementById("randompic").src = store;
console.log(store);
});
Same here, I did use console.log just for test the value is correct and I used to change the randompic ID related image src html to the randomly chosen image.
Hopefully I did helping those people who are newbie as me.
I'm using the grails elasticsearch plugin in my application, and I am running across an odd exception.
I have a method that builds a request using a geo_distance filter that way:
def activityList = ElasticSearchService.search(
[types:[DomainA, DomainB],
sort: orderBy, order: orderAs, size: (int)maxRes],
{
// bla bla bla some working closure building a working query
}
if(centerLat != -1){
filter{
geo_distance(
'distance': searchRadius,
'activityLocation': [lat: (Double)centerLat, lon: (Double)centerLon]
)
}
}
}
)
And whenever I try to use the method with the filter (that is, when I set for example searchRadius to '5km' and centerLat/ centerLon to correct coordinates, my ElasticSearch node goes crazy and keeps logging the following error until I shut it down:
| Error 2014-08-27 10:31:49,076 [elasticsearch[Agent Zero][bulk][T#2]] ERROR index.IndexRequestQueue - Failed bulk item: MapperParsingException[failed to parse]; nested: ElasticsearchParseException[field must be either 'lat', 'lon' or 'geohash'];
I tried looking around the web for the reason why this MappingParserException is thrown, and I ended up looking at the source code for the org.elasticsearch.common.geo.GeoUtils class. Apparenty, the exception is thrown because my lat and lon fields are not numbers (see lines 372 and 381).
Why is this happening? Did I declare my filter wrong?
I think you have a problem is with your index types mapping, in order to understand what is the problem you have to post some example of the data you are indexing and type mappings (you can get your current mappings from host:port/{index}/_mapping/{type}).
Try to define the mapping as explained here: http://noamt.github.io/elasticsearch-grails-plugin/guide/mapping.html look at 3.3.2 GeoPoint, make sure you define your data points correctly.
Assuming the mapping for activityLocation is "geo_point" then you shouldn't need to preface your coordindate with "lat" and "lon" and should just be able to send
'activityLocation': [(Double)centerLat,(Double)centerLon]
I think this "lat" "lon" preface might have been supported as a geo_point format in earlier versions, but as of 1.0.0 I don't think it still is.
It's been a while and this problem made me lose my nerves quite a bit, but I have finally solved it.
I was mapping the following classes that way:
class A{
static searchable={
activityLocation geoPoint:true, component:true
// some other mappings on some other fields
}
Location activityLocation
// some other fields
}
a
class Location{
static searchable = true
String locationName
Double lat
Double lon
}
There were two problems:
I didn't want to use the root false option when mapping my activityLocation objects, because I wanted to be able to search them directly, which caused my A objects to contain the following property (note the presence of the id field):
'activityLocation' : { 'id':'1', 'locationName' : 'foo', 'lat': '42.5464', 'lon': '65.5647' }
which isn't a geoPoint because it has more than just a lat and lon field.
I was mapping the locationName property as part of my activityLocation objects, which makes them not geoPoints.
I ended up solving the problem by changing the mapping to the following values for activityLocation:
ActivityLocation{
static searchable = {
only = ['lat', 'lon']
root false
}
String locationName
Double lat
Double lon
}
This solved my problem and my search went well from then on.
I have to add that I was pretty confused by the docs regarding this and I am a bit disappointed that I can't map a geoPoint with more attributes. I wish it were possible to have other fields in the mapping.
Furthermore, I wish the plugin gave me better access to the ES logs, it took me a while to figure out where to look for the error code.
I have managed to fix this with few lines of coded added to "DeepDomainClassMarshaller.groovy" and overriding this file.
Previous code:-
if (DomainClassArtefactHandler.isDomainClass(propertyClass)) {
String searchablePropertyName = getSearchablePropertyName()
if (propertyValue.class."$searchablePropertyName") {
// todo fixme - will throw exception when no searchable field.
marshallingContext.lastParentPropertyName = prop.name
marshallResult += [(prop.name): ([id: propertyValue.ident(), 'class': propertyClassName] + marshallingContext.delegateMarshalling(propertyValue, propertyMapping.maxDepth))]
} else {
marshallResult += [(prop.name): [id: propertyValue.ident(), 'class': propertyClassName]]
}
// Non-domain marshalling
}
New Code:-
if (DomainClassArtefactHandler.isDomainClass(propertyClass)) {
String searchablePropertyName = getSearchablePropertyName()
if (propertyValue.class."$searchablePropertyName") {
// todo fixme - will throw exception when no searchable field.
marshallingContext.lastParentPropertyName = prop.name
if(propertyMapping?.isGeoPoint())
marshallResult += [(prop.name): (marshallingContext.delegateMarshalling(propertyValue, propertyMapping.maxDepth))]
else
marshallResult += [(prop.name): ([id: propertyValue.ident(), 'class': propertyClassName] + marshallingContext.delegateMarshalling(propertyValue, propertyMapping.maxDepth))]
} else {
marshallResult += [(prop.name): [id: propertyValue.ident(), 'class': propertyClassName]]
}
// Non-domain marshalling
}
Let me know in case issue still persists.
Note:- I am still using elasticsearch:0.0.3.3.
I was trying to use angular dart with websockets/server sent events and could not find any documentation/examples (there are some for angularJS but that seems very different for such things). A few things I tried also did not work.
Does anyone know how to do this?
Here is one version of what I tried and the error:
#NgController (
selector: "ACdistribution",
publishAs : "dstbn")
class ACDstbnController{
List <WtdPres> distbn;
void updateDstbn(List<WtdPres> newdstbn){
distbn = newdstbn;
}
final dstbnsrc = new EventSource("../dstbns")
..onMessage.listen((event){
List wps = JSON.decode(event.data);
List <WtdPres> newdistbn = wps.map((wp) => new WtdPres.fromJson(wp));
updateDstbn(newdistbn);
});
}
The error I got in pub build was:
web/provingground.dart:55:5:
'updateDstbn' is only available in instance methods.
updateDstbn(newdistbn);
^^^^^^^^^^^
There are limitations on what you can do on initializers for final fields.
Can you try to put this code inside the constructor
var dstbnsrc;
ACDstbnController() {
dstbnsrc = new EventSource("../dstbns")
..onMessage.listen((event){
List wps = JSON.decode(event.data);
List <WtdPres> newdistbn = wps.map((wp) => new WtdPres.fromJson(wp));
updateDstbn(newdistbn);
});
}
I'm using the Atmosphere plugin in a Grails application to make Ajax push calls to the client. The basic architecture is, I have a loop in the server which creates the data that I want to push to the browser, so in every iteration it uses the atmosphere broadcast() method to send the data to the client.
It works fine when I use it outside the loop, like this:
def builder = new JSONBuilder()
def jsonResult = builder.build{
artist = "incubus"
location = {
lat = 45.678909
lng = -14.45667
}
}
broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
However, when I use it programmatically inside the loop, the browser throws the error: An invalid or illegal string was specified" code: "12, and doesn't work properly.
A simplified example of the loop is as follows:
[[lat:45.678909,lng:-14.45667],[lat:32.56433,lng:22.4566]].each{
def builder = new JSONBuilder()
def jsonResult = builder.build{
artist = "incubus"
location = {
lat = '"${it.lat}"'
lng = '"${it.lng}"'
}
}
broadcaster['/atmosphere/recommend'].broadcast(jsonResult)
}
Any ideas why is this happening?
Thanks!
I think it should work, if you remove the quotes.
location = {
lat = it.lat
lng = it.lng
}
Christian