Dynamic Icons in Flutter - database

I retrieve some data from my DB, where I have a Column called "icon" in which I stored some Strings. For each of them, I want to pass in the Icon class of Flutter, charging the corresponding Icon.
I have the single String inside
items[index]["icon"]
But I can't pass it inside Icon(items[index]["icon"])
How can I do?

You can use the icons directly with their literal names by accessing the Material Icons font directly with Text() widget.
Example:
Text(
'perm_contact_calendar',
style: TextStyle(fontFamily: 'MaterialIcons'),
);
You may use it for custom Icon class to integrate with Material Framework smoothly, but in this case you will need a --no-tree-shake-icons flag for build command since non-constant IconData constructor breaks icon tree shaking.

This might help someone in the future.
You do not need to use any Map to create an icon from dynamic name (too much copy-pasting).
Instead of icon names you can use icon's numeric identifier from the Icons Class.
Example:
int iconCode = 58840;
// Will display "Up arrow" icon from the list
Icon(IconData(iconCode, fontFamily: 'MaterialIcons'));

You need a mapping from string to your icon either Icons or FontAwesomeIcons or ...
Map<String, IconData> iconMapping = {
'facebook' : FontAwesomeIcons.facebook,
'twitter' : FontAwesomeIcons.twitter,
'home' : FontAwesomeIcons.home,
'audiotrack' : Icons.audiotrack,
};
#override
Widget build(BuildContext context) {
return Icon(iconMapping [icon], color: HexColor(color));
}
similar question and answer
Trying to dynamically set the Icon based on a JSON string value
Flutter: Show different icons based on value

Try this out. this is exact thing you are looking for.
Widget buildRemoteIcon(){
// var remoteIconData = new RemoteIconData(Icons.add); // -> flutter native material icons
// var remoteIconData = new RemoteIconData("material://Icons.add"); // -> native material icons remotely (dynamically)
// var remoteIconData = new RemoteIconData("https://example.com/svg.svg"); // -> loading remote svg
// var remoteIconData = new RemoteIconData("assets/icons/add.png"); // -> loading local assets
// var remoteIconData = new RemoteIconData("custom-namespace://CustomIcons.icon_name"); // -> (requires pre-usage definition)
var remoteIconData = new RemoteIconData();
return RemoteIcon(icon: remoteIconData, color: Colors.black);
}
https://github.com/bridgedxyz/dynamic/tree/master/flutter-packages/x_icon
https://pub.dev/packages/x_icon

Use This Package From here you can get Material Icons + FontAwesome Icons also you just need to pass the icon name.
https://pub.dev/packages/dynamic_icons

Related

REACT I want to create an ARRAY with the names of the files of the images in the PUBLIC FOLDER

REACT I want to create an ARRAY with the names of the files of the images in the PUBLIC FOLDER but can`t reach them because they aren't in the SCR folder.
Surely is something basic but i'm missing it.
enter image description here
To access the public folder, you have to use process.env.PUBLIC_URL or %PUBLIC_URL%:
<img src="%PUBLIC_URL%/images/some_image.png" />
Or, alternatively using Javascript as you want an array:
const images = ['image_1.png', 'image_2.png']
return images.map(image => <img src=`${process.env.PUBLIC_URL}/images/${image}`
As far as I know, there is no way to iterate through all the files in the public folder as webpack has no access to it. You would have to manually enumerate them.
If you instead use the src folder, it is possible to use import to dynamically using Regez. It looks like this (taken from here):
function importAll(r) {
let images = {};
r.keys().map((item, index) => { images[item.replace('./', '')] = r(item); });
return images;
}
const images = importAll(require.context('./images', false, /\.(png|jpe?g|svg)$/));
By the way, unless you have a strong reason not to use the src folder (for example, images are used outside of Javascript or outside of the React project), it is recommended to add all files inside the src folder as webpack can do additional optimizations, such as inlining (ie: using Data URI) images.
I'm not sure I understood your question, you want to dynamically create an array in the code inside your ReactJS app?
For instance, if '/public/image' contains 'img1.png', 'img2.png', you'd get
myArray = ['img1.png', 'img2.png']

how to update google chart?

Am new to angularjs/googlecharts and learning on the job. I've the following code in my controller which renders the piechart initially and has no issues.
There is a slider directive, which when changed (basically a date range slider), should update the columnchart with new data. But I don't know how to update the piechart data. I do get the new data from the backend without any problems though.
Here is the initialization code in controller:
$scope.piechart = {};
$scope.piechart.type ='PieChart';
piechartData = response.data.piechart;
var piechartoptions = {
'min-width':800,
'max-width':320,
'is3D':true,
'pieSliceText': 'label',
'pieSliceTextStyle': {fontSize: 10},
'chartArea' : { left: 30, top: 60 },
'backgroundColor': {fill:'transparent'},
'legend': {'textStyle':{'color': 'white',
'fontSize': 12},
'position': "top",
'maxLines':10,
'alignment':"start"},
'height':500
};
$scope.piechart.data = new google.visualization.DataTable(piechartData);
$scope.piechart.options = piechartoptions;
$scope.piechart.formatters = {};
In the directive (which is used in the html that the above controller's scope resides in), I've access to the chart like the following:
scope.$parent.piechart
So in a very naive way i did this but to no avail:
scope.$parent.piechart.data = new google.visualization.DataTable(response.data.piechart)
TIA for all the help.
I bumped into this issue today. An easy quick fix is to simply write
this.chartData = Object.assign([], this.chartData) to reassign to the exposed dataset property into your component so it triggers change detection.
More information from this issue in a different library:
valor-software/ng2-charts#959 (comment)
Hope this helps weary travellers :)
To achieve this you need to create watch on your slider model so when it gets change you need to update your pie chart model so it'll automatically update.
Watch
$scope.$watch('sliderModel',function(n,o) {
// update your new pie chart data here, I think you need to update below model only
$scope.piechart.data = new google.visualization.DataTable(piechartData);
}
It just an example. You have to update it with new data for pie chart.
Proper Angular way to use google chart
You should use google-chart directives to plot pie chart so this kind of problems will be solved automatically.
Have a look here - Angular-google-chart

How to get the text from webpage using coded ui

I am new for coded ui and I have got stuck for processing message display on webpage. As we used to get text from web page in selenium using method getText(), is such kind of possibility are available in coded ui.?
I would appreciate your help!!!!
Thanks,
Dani
updated - 5/14/2014
script code:
public void FPInternetExplorer()
{
#region Variable Declarations
HtmlEdit uIUserNameEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIUserNameEdit;
HtmlEdit uIPasswordEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIPasswordEdit;
HtmlInputButton uILoginButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UILoginButton;
HtmlEdit uISecurityQuestionAnswEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UISecurityQuestionAnswEdit;
HtmlInputButton uIValidateButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIValidateButton;
#endregion
this.UIInternetExplorerEnhaWindow6.LaunchUrl(new System.Uri(this.FPInternetExplorerParams.UIInternetExplorerEnhaWindow6Url));
// Type 'test#test.test' in 'User Name' text box
uIUserNameEdit.Text = this.FPInternetExplorerParams.UIUserNameEditText;
// Type '{Tab}' in 'User Name' text box
Keyboard.SendKeys(uIUserNameEdit, this.FPInternetExplorerParams.UIUserNameEditSendKeys, ModifierKeys.None);
// Type '********' in 'Password' text box
uIPasswordEdit.Password = this.FPInternetExplorerParams.UIPasswordEditPassword;
// Click 'Login' button
Mouse.Click(uILoginButton, new Point(62, 19));
//Code to get the text from div tag. This is the code I have added
HtmlDiv testLabel = new HtmlDiv();
testLabel.SearchProperties[HtmlDiv.PropertyNames.Id] = "SecurityQuestion_AnswerText";
string myText = testLabel.InnerText;
Console.Write("myText " + myText);
// Type 'Computer' in 'SecurityQuestion.AnswerText' text box
uISecurityQuestionAnswEdit.Text = this.FPInternetExplorerParams.UISecurityQuestionAnswEditText;
// Type '{Tab}' in 'SecurityQuestion.AnswerText' text box
Keyboard.SendKeys(uISecurityQuestionAnswEdit, this.FPInternetExplorerParams.UISecurityQuestionAnswEditSendKeys, ModifierKeys.None);
// Click 'Validate' button
Mouse.Click(uIValidateButton, new Point(81, 25));
}
// When run this code using coded UI, system gives exception: Message - 'To test Windows Store apps, use the Coded UI Test project template for Windows Store apps under the Windows Store node.' Is something missing in this code? Would appreciate if you could provide link to configure missing component
The property you're looking for is "InnerText". So, for example, on a hyperlink like:
HtmlHyperlink target = new HtmlHyperlink();
target.SearchProperties[<search property>] = <value>;
string myText = target.InnerText;
You can extrapolate this to just read all of the text on the page by selecting the outer container of the page and getting the InnerText of it, then parse through the string for what you want, but I've found it a lot simpler if you work in the most focused object.

Removing a fMath image properties dialog in ckeditor

I am a bit stuck with this so it would be great if you could help.
I am using Drupal 7 and Ckeditor 4.3. I am developing a site which has fmath equation editor integrated.
I have disabled the image button, as I don't want end users being able to upload their own images. On the other hand, users can use fMath to insert equations. The way fMath handles equation insertion is by inserting a img tag.
When users double click this image or when they right click over the image, they access the image properties dialog, where they can change source url of the image and few other things. On the url input text, they could change the source of the image so that they could insert their own images on the page, which is something I don't want.
The have been working with two different unsuccessful approaches until now trying to solve this problem:
Removing elements from the dialog, as the URL input text on the dialog (and the alt text as well).
Trying to disable the dialog itself.
I'd like to use a custom plugin to accomplish the desired behavior as I have different CKeditor profiles in Drupal.
I haven't been successful. Do you know how could I handle this undesirable behavior?
Ok, I ended up with something like this in the plugin.js file:
CKEDITOR.plugins.add( 'custom_doubleclick',
{
init: function( editor )
{
// First part, dialogDefinition allow us to remove the
// "Link" and "Advanced" tabs on the dialog
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'image' ) {
dialogDefinition.removeContents( 'Link' );
dialogDefinition.removeContents( 'advanced' );
}
});
// Second part, it disables the textUrl and txtAlt input text boxes
editor.on( 'dialogShow', function( ev ) {
var dialog = ev.data;
var dialogName = dialog.getName();
if ( dialogName == 'image' ) {
//var dialog = CKEDITOR.dialog.getCurrent();
// Get a reference to the Link Info tab.
console.log(dialog)
dialog.getContentElement( 'info','txtUrl' ).disable();
dialog.getContentElement( 'info','txtAlt' ).disable();
}
});
}
});
As you can see I didn't disable the dialog itself, but the non useful elements. I hope this can help to someone else.

How to set Border/Background on CanvasLayout based Custom Widget in Qooxdoo?

I'm new to Qooxdoo (i'm using version 0.7.4, because I'm using Eclipse RAP) and I'm try to create a Custom Widget based on CanvasLayout class, that composites another Widgets. Here little peace of code:
qx.Class.define( "my.CanvasWidget", {
extend: qx.ui.layout.CanvasLayout,
construct: function( id ) {
this.base( arguments );
...
}
}
} );
//If using:
var myCanvasWidget = new my.CanvasWidget("myId");
...
myCanvasWidget.setBackgroundColor("#ff0000");
My question is: the setBackgroundColor has no effort on myCanvasWidget, why is it so (The property backgroundColor exist in super Class "Widget")?
It depends on the size of your CanvasLayout widget. Setting the size (height and width) of it will show you the background color.
// in the constructor of your widget
this.setWidth(100); // 100 for example
this.setHeight(100);
As it is 0.7.x, the size information, as far as I know, will not be calculated automatically so you have to take care of that yourself.

Resources