I have this map:
{4: 5, 3: 5, 2: 6, 5: 2, 6: 1, 0: 1, 8: 1, 1: 1}
where the first key is a code from this list
static final List<SensationItem> sensationList = [
SensationItem(
code: 0,
title: 'Formicolio / Intorpidimento'),
SensationItem(
code: 1,
title: 'Sudorazione intensa'),
SensationItem(
code: 2, title: 'Dolore al petto'),
SensationItem(code: 3, title: 'Nausea'),
SensationItem(code: 4, title: 'Tremori'),
SensationItem(
code: 5,
title: 'Paura di perdere il controllo',
SensationItem(
code: 6,
title: 'Sbandamento / Vertigini'),
SensationItem(
code: 7, title: 'Palpitazioni'),
SensationItem(
code: 8,
title: 'Sensazione di soffocamento'),
];
}
I want to replace first key with code from sensationList
like something below
var result = ['Formicolio / Intorpidimento',1];
var result2 = ['Sudorazione intensa',8];
var result3 = ['Nausea',5];
var result4 = ['Palpitazioni',15];
.
.
.
.
This will give you a List<List<Object>>:
final result = myMap.entries
.map((entry) => [
sensationList
.firstWhere((element) => element.code == entry.key)
.title,
entry.value
])
.toList();
print(result);
// ([Tremori, 5], [Nausea, 5], [Dolore al petto, 6], ..., [Sensazione di soffocamento, 1], [Sudorazione intensa, 1])
Related
var generateEvents = function () {
var eventData = [];
var eventSubjects = [
'Bering Sea Gold', 'Technology', 'Maintenance', 'Meeting', 'Travelling', 'Annual Conference', 'Birthday Celebration',
'Farewell Celebration', 'Wedding Anniversary', 'Alaska: The Last Frontier', 'Deadliest Catch', 'Sports Day', 'MoonShiners',
'Close Encounters', 'HighWay Thru Hell', 'Daily Planet', 'Cash Cab', 'Basketball Practice', 'Rugby Match', 'Guitar Class',
'Music Lessons', 'Doctor checkup', 'Brazil - Mexico', 'Opening ceremony', 'Final presentation'
];
var weekDate = new Date(new Date().setDate(new Date().getDate() - new Date().getDay()));
var startDate = new Date(weekDate.getFullYear(), weekDate.getMonth(), weekDate.getDate(), 10, 0);
var endDate = new Date(weekDate.getFullYear(), weekDate.getMonth(), weekDate.getDate(), 11, 30);
eventData.push({
Id: 1,
Subject: eventSubjects[Math.floor(Math.random() * (24 - 0 + 1) + 0)],
StartTime: startDate,
EndTime: endDate,
Location: '',
Description: 'Event Scheduled',
RecurrenceRule: 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;INTERVAL=1;COUNT=10;',
IsAllDay: false,
IsReadonly: false,
CalendarId: 1
});
I have tried inspecting the code and tried to add the input field eventData, but not working. I want to add the Input field of my choice and want to send the input field data to the firestore database.
hello i have an object Json which have some values as payload , key , card .. so i aim to get the data i need directly with key "payload" .
var dataFinal= tag.data.toString();
and this what i get if i print my data
[log] handle {nfca: {identifier: [12, 4, 18, 17], atqa: [4, 0], maxTransceiveLength: 253, sak: 8, timeout: 618}, mifareclassic: {identifier: [99, 4, 150, 17], blockCount: 64, maxTransceiveLength: 253, sectorCount: 16, size: 1024, timeout: 618, type: 0}, ndef: {identifier: [99, 4, 150, 17], isWritable: true, maxSize: 716, canMakeReadOnly: false, cachedMessage: {records: [{typeNameFormat: 1, type: [84], identifier: [], payload: [1,45,989]}]}, type: com.nxp.ndef.mifareclassic}}
how can i get the payload value ?
You can check out the function jsonDecode() which expects a string as a param and returns dynamic or Map in your case
import 'dart:convert';
Map<String,dynamic> data = jsonDecode(tag.data.toString());
print(data["nfca"]);
I've made this extension on an enumm which has a static function toSelectList(), but when I try to use the extension, the toSelectList() is not recognised. I have had this issue before in VSCode, so I understand the IDE may sometimes show a warning, but the warning should go away and this time it isn't. The only fix that has worked is to use the extension and not use the original enum being extended. My code:
The enum and extension (grocery_item_categories_enum.dart):
import 'package:vepo/src/presentation/widgets/form_widgets/select/common/card_select_list_item/card_select_list_item.dart';
enum GroceryItemCategoryEnum {
meat,
dairy,
baking,
condiments,
cooking,
confectionary,
dessert,
healthFood,
}
extension GroceryItemCategoryExtension on GroceryItemCategoryEnum {
static const items = {
GroceryItemCategoryEnum.meat:
CardSelectListItem(label: 'Meat', id: 1, iconCodePoint: 0xf814),
GroceryItemCategoryEnum.dairy:
CardSelectListItem(label: 'Dairy', id: 2, iconCodePoint: 0xf7f0),
GroceryItemCategoryEnum.baking:
CardSelectListItem(label: 'Baking', id: 3, iconCodePoint: 0xf563),
GroceryItemCategoryEnum.condiments:
CardSelectListItem(label: 'Condiments', id: 4, iconCodePoint: 0xf72f),
GroceryItemCategoryEnum.cooking:
CardSelectListItem(label: 'Cooking', id: 5, iconCodePoint: 0xe01d),
GroceryItemCategoryEnum.confectionary: CardSelectListItem(
label: 'Confectionary', id: 6, iconCodePoint: 0xf819),
GroceryItemCategoryEnum.dessert:
CardSelectListItem(label: 'Dessert', id: 7, iconCodePoint: 0xf810),
GroceryItemCategoryEnum.healthFood:
CardSelectListItem(label: 'Health Food', id: 8, iconCodePoint: 0xf787),
};
CardSelectListItem get item => items[this];
static List<CardSelectListItem> toSelectList() {
return const [
CardSelectListItem(label: 'Meat', id: 1, iconCodePoint: 0xf814),
CardSelectListItem(label: 'Dairy', id: 2, iconCodePoint: 0xf7f0),
CardSelectListItem(label: 'Baking', id: 3, iconCodePoint: 0xf563),
CardSelectListItem(label: 'Condiments', id: 4, iconCodePoint: 0xf72f),
CardSelectListItem(label: 'Cooking', id: 5, iconCodePoint: 0xe01d),
CardSelectListItem(label: 'Confectionary', id: 6, iconCodePoint: 0xf819),
CardSelectListItem(label: 'Dessert', id: 7, iconCodePoint: 0xf810),
CardSelectListItem(label: 'Health Food', id: 8, iconCodePoint: 0xf787),
];
}
}
Trying to use it:
import 'package:vepo/src/domain/constants/grocery_item_categories_enum.dart';
#override
List<Widget> createItemCategoriesFormWidgets({BuildContext context}) {
return [
VpSelectMultipleCards(listItems: GroceryItemCategoryEnum.toSelectList())
];
}
compile time error:
The argument type 'dynamic' can't be assigned to the parameter type 'List<CardSelectListItem>'.dart(argument_type_not_assignable)
The method 'toSelectList' isn't defined for the type 'GroceryItemCategoryEnum'.
Try correcting the name to the name of an existing method, or defining a method named 'toSelectList'.dart(undefined_method)
How do I use this extension method toSelectList() without the IDE showing an error.
You can declare static methods in an extension, but they are static on the extension itself.
You should therefore call toSelectList() on GroceryItemCategoryExtension and not on GroceryItemCategory.
Basic example on String:
void main() {
// print(String.getMyString());
// The method 'getMyString' isn't defined for the type 'String'
print(StringX.getMyString());
}
extension StringX on String {
static String getMyString() => "MyString";
}
I am using Google Chart Calendar and I would like to modify the gradient values - min and max. From the official documentation I can do it by modifying colorAxis:
{minValue: 0, maxValue: 5, colors: ['#FF0000', '#00FF00']}
But it supports only type number and I would prefer to indicate it by using string, something like "Lowest value" for minValue and "Highest value" for maxValue.
Any suggestions how can I do it?
in order to calculate the gradient on the 'Activity' column,
options for minValue and maxValue can only be numbers...
but if you just want to change the label that is displayed on the legend,
that can be done manually on the chart's 'ready' event
see following working snippet...
google.charts.load('current', {
packages: ['calendar']
}).then(function () {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({type: 'date', id: 'Date'});
dataTable.addColumn({type: 'number', id: 'Activity'});
dataTable.addRows([
[new Date(2018, 0, 3), 1],
[new Date(2018, 0, 16), 2],
[new Date(2018, 1, 6), 3],
[new Date(2018, 1, 15), 4],
[new Date(2018, 1, 25), 5]
]);
var chart = new google.visualization.Calendar(document.getElementById('chart_div'));
var options = {
colorAxis: {minValue: 0, maxValue: 5, colors: ['#FF0000', '#00FF00']},
width: 1000
};
google.visualization.events.addListener(chart, 'ready', function () {
if ($('#chart_div text').length > 1) {
$($('#chart_div text').get(0)).text('Lowest');
$($('#chart_div text').get(1)).text('Highest');
}
});
chart.draw(dataTable, options);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
I am playing around with Google Chart to look a certain way. In this situation I have a combo chart a line and column chart.
I have stumble upon a view "layout" problems
How do replace the show2r legend with just some custom text? At
the moment says: y = 2.032E-4 * x - 8.203 r^2 = 7.005E-3 and I want
to replace it with "Trendline (Lineair)
2/ Also the legend gets a
1/2 and Arrows left and right. I like the legend to always be
visible?
3/ The x axis doesn't display all dates, how can I set that
as a default?
4/ How do I add vertical line in say month June??
Regards
to change the trendline label in the legend, use option --> labelInLegend
there are no standard options to change the value in the tooltip,
but it can be changed manually using event --> onmouseover
when the legend's position is top,
you can use option --> legend.maxLines
to increase the number of lines available and prevent the arrows...
to ensure all dates are shown on the x-axis,
allow enough room by using option --> chartArea.bottom
see following working snippet for examples of each...
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['x', 'y0', 'y1'],
[new Date(2017, 11, 28), 175, 10],
[new Date(2017, 11, 29), 159, 20],
[new Date(2017, 11, 30), 126, 35],
[new Date(2017, 11, 31), 129, 40],
[new Date(2018, 0, 1), 108, 60],
[new Date(2018, 0, 2), 92, 70]
]);
var options = {
chartArea: {
bottom: 72
},
hAxis: {
slantedText: true
},
height: 400,
legend: {
maxLines: 2,
position: 'top'
},
tooltip: {
isHtml: true
},
trendlines: {
0: {
labelInLegend: '0-Linear Trend',
showR2: true,
type: 'linear',
visibleInLegend: true
},
1: {
labelInLegend: '1-Linear Trend',
showR2: true,
type: 'linear',
visibleInLegend: true
}
},
width: 400
};
var container = document.getElementById('chart_div');
var chart = new google.visualization.ColumnChart(container);
google.visualization.events.addListener(chart, 'onmouseover', function (props) {
var tooltipLabels = container.getElementsByTagName('span');
for (var i = 0; i < tooltipLabels.length; i++) {
if (tooltipLabels[i].innerHTML.indexOf('y =') > -1) {
tooltipLabels[i].innerHTML = 'CUSTOM TEXT:';
}
}
});
chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>