Process of List.generate Constructor in Dart - dart

I am new to Flutter and Dart. I am trying to create long List View in Flutter. but I am stuck with this Constructor. Can anyone explain how this Constructor works?
List<String> = List<String>.generate(1000,(counter) => "Item $counter");

The following:
List<String>.generate(1000,(counter) => "Item $counter");
will generate a List of 1000 items, where each item are in order:
"Item 0"
"Item 1"
"Item 2"
...
"Item 999"

List<String> = List<String>.generate(1000,(counter) => "Item $counter");
this will generate 1000 item and you can manipulate each item threw your arrow function that takes counter as a parameter in that case counter will be ur index each time .
the output will be :
"Item 0"
"Item 1"
"Item 2"
...
"Item 999"

List.generate can be very useful if you know the length and structure of the list you like to create.
For example: You can create a List of maps too
Here generating a list with day e.g Mon, Tue,Wed,etc.. for the whole week
see the 7 as the number of iterations.
final myList = List.generate(7, (index) {
final dateFormatted =DateTime.now().subtract(Duration(days:index));
return {
'day':DateFormatted.E().format(dateF),
'date':dateFormatted,
};
});
print(myList);

Related

How to print block_data based on block_type key value in dart

I have a method where i iterate through list of objects. For each object i want to print the value of 'block_data' based on "block_type" in the order of above to below. Notice that sometimes the block_type title is above text and sometimes its below text in the list of objects.
Sometimes i have other block_types like graph-pie-chart and i have block_labels for the chart and the block_data for the chart is also in a list based on block_labels. And all the block_type in the List coul be something else and another order. But i still want it in the order of the List of objects i get like the example below. I wonder how i can achieve this with dart?
class Book {
getBookInfo() {
final List listOfItems = [
{"block_type": "title", "block_data": "Books"},
{"block_type": "text", "block_data": "This is the textblock of books"},
{"block_type": "text", "block_data": "This is the textblock of publishers"},
{"block_type": "title", "block_data": "Publishers"},
{"block_type": "graph-pie-chart", "block_labels": ["Total sold","Sold copies","Reviews"], "block_data": ["3000", "100", "10"]},
{"block_type": "button", "link": "<link to a bookshop>"},
];
List selectedItem = listOfItems;
selectedItem.forEach((index) {
}
;
});
}
}
While strictly speaking, you are not incorrect to call each element of the list an object, they are more precisely of type Map<String,String>
You can use .where() to filter out maps that do not have a key of block_type and value of the block type that you need, then do your .forEach() to print the value you want.
You also might consider defining a class type to use instead of a Map in your listOfItems

Swagger v3 - Selecting multiple values from given set of values

I have a parameter that a list of Strings, but the values must belong from a set of values.
This is what I have tried
#Parameter(description = "The type of status filters", content = #Content(array = #ArraySchema(schema = #Schema(implementation = String.class, allowableValues = {"Option 1", "Option 2", "Option 3"}))))
What I'm currently getting
As you can see, there is a text field.
I would like to have a drop-down instead.
Any suggestions on how to do it?
Solved by removing the implementation part
#Parameter(description = "The type of status filters", content = #Content(array = #ArraySchema(schema = #Schema(allowableValues = {"Option 1", "Option 2", "Option 3"}))))

Adding new Mantis status but ran out of enumeration values

I was wondering if you had any thoughts about this issue: We want to add one more status at a specific 'place' between two statuses, but we ran out of enumeration for it.
The enumeration looks like this:
$s_status_enum_string = "10:new,20:feedback,40:confirmed,50:assigned,52:in progress,53:code review pending,54:merge pending, 56:merged, 58:resolved, 60:testing, 70:tested, 90:closed, 91:updating test documentation";
And I want to add a new status between 52 and 53 so that, on the pull-down menu for status, they appear in the desired order.
I tried different things - including changing the .php file definitions then updating the MySQL table's status field in mantis_bug_table, but it messes up all the views and filters.
Any ideas?
The following steps might help you:
Redefine the enumeration string as per your requirements
Prepare a traceability with your current enumeration values
Update the status field in bugs table with the new values
Add the enumeration in config.php
You may have to reset your previous filters. The filter criteria is stored as a serialized string and it's very difficult to modify.
If anyone is having issues with this you need to change the following:
In config_inc.php modify $g_status_enum_string to ennumerate the new statuses as you see fit.
In custom_constants_inc.php make sure to do the same as above.
In the database, run SQL commands such as this:
UPDATE mantisclone.mantis_bug_table SET status=100 WHERE status=10;
to change the actual records for existing status IDs to new ones.
In custom_strings_inc.php modify $s_status_enum_string and input your new statuses. For example one of mine was:
$s_sanity_test_bug_title = "Set Issue Sanity Test";
$s_sanity_test_bug_button = "Issue Sanity Test Pending";
$s_email_notification_title_for_sanity_test = "The following issue is NOW SANITY TEST PENDING";
Finally you'll need a small script to change the existing ennumerated values in mantis_filters_table. This was mine, alter it as you see fit:
<?php
$mantisDB="myMantisDatabaseName";
mysql_connect("localhost", "XXXX", "YYYY") or die("Could not connect: " . mysql_error());
mysql_select_db($mantisDB);
$result = mysql_query("SELECT id, filter_string FROM $mantisDB.mantis_filters_table");
function parseRecord($statusArray)
{
$newStatus = array( "10" => "100",
"20" => "200",
"50" => "300",
"52" => "400",
"53" => "500",
"54" => "540",
"56" => "560",
"58" => "580",
"60" => "600",
"70" => "700",
"75" => "450",
"90" => "900",
"91" => "910"
);
foreach ($statusArray as $key=>$value)
{
if(array_key_exists($value, $newStatus))
{
echo "Found value $value, replacing it with " . $newStatus[$value] . "\n";
$statusArray[$key] = (int)$newStatus[$value];
}
}
}
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$statusID = $row["id"];
$serializedString = $row["filter_string"];
$unserializedArray = unserialize(substr($serializedString,3)); // There's a prepended 'v8#' string in there, don't know why.
parseRecord(&$unserializedArray["hide_status"]);
parseRecord(&$unserializedArray["show_status"]);
$newSerialized = "v8#".serialize($unserializedArray);
// echo $newSerialized;
$changeStatus = mysql_query("UPDATE $mantisDB.mantis_filters_table SET filter_string='$newSerialized' WHERE id=$statusID");
}
mysql_free_result($result);
?>
I hope this works, let me know if you're having any issues.

SAPUI5 - complex model binding

I have this json model:
model/data.json
{
"orders" : [
{
"header" : { "id" : "00001", "description" : "This is the first order" },
"items" : [
{ "name" : "Red Book","id" : "XXYYZZ" },
{ "name" : "Yellow Book", "id" : "AACCXX" },
{ "name" : "Black Book", "id" : "UUEEAA" },
]
},
{
// another order with header + items
},
.....
]
}
and I'm assigning it onInit to the view, like this:
var model = new sap.ui.model.json.JSONModel("model/data.json");
sap.ui.getCore().setModel(reqModel);
I'm trying to display a list of orders in the first view (showing the id), like this:
var list = new sap.m.List({
id: "mainList",
items: []
});
var items = new sap.m.ActionListItem({
text : "{id}",
press : [ //click handler, onclick load the order details page ]
});
list.bindItems("/orders", items);
.... // add list to the page etc etc
What I cannot do, is connect each order to its header->id.. I tried
text: "/header/{id}"
text: "{/header/id}"
in the items declaration, and
list.bindItems("/orders/header", items)
in the list binding, but none of them works.. The id value is not displayed, even though a "blank" list item is shown..
Any idea? What am I doing wrong?
Thank you
The solution was one of those I tried (but I don't know why it didn't work at that time)
text: "{/header/id}"
The ListItem acts as a Template for a list/array of objects. That's why you bind it against an array structure in your data:
list.bindItems("/orders", itemTemplate)
That makes bindings of the ListItem relative to /orders and therefore your item should look like this without leading '/' (absolute paths would look like this /orders/0/header/id asf.):
var itemTemplate = new sap.m.ActionListItem({
text : "{header/id}",
press : [ //click handler, onclick load the order details page ]
});
Not quite sure how you made it work the way you have shown... May be it's not as picky as I thought.
Btw: For whatever reason the ResourceModel builds an exception of that syntax. You can always omit the leading '/' when dealing with ResourceModels (probably because they do not allow nested structures).
BR
Chris
Cannot add comments yet, therefore an answer to you solved Problem, that could answer the initial problem. (And inform People using that example in any way)
In the current code listing you use the variable "reqModel" to set the model, but the variable with the model in it is named "model" in the line before. Maybe that was the first reason why both of your examles would not work?
Perhaps this error was cleared on rewriting some passages while testing.
greetings! -nx

How do I get Choice Values from a Document library's Choice column in code

I am fairly new to SharePoint development and as you may all know that it is very basic for one to know how to access fields in a choice column...
My problem:
I want to access the values of the Check Boxes from a Choice Column.
For Example:
I have a document library called Libe, this document library has a custom column with type Choice and has 4 checkboxes with the values:
Category 1
Category 2
Category 3
Category 4
How do I get the values like literally the text values of what is in the Check Box List: "Category 1", "Category 2" ... "Category 4".
Any ideas?
I can access the column fine and get the selected values, I just do not know how to get the values the user can choose from.
Answer
SPFieldMultiChoice Fld = (SPFieldMultiChoice)list.Fields["Column"];
List<string> fieldList = new List<string>();
foreach (string str in Fld.Choices)
{
fieldList.Add(str);
}
Above is the answer, I can't answer my own question until I have a 100 rep.
using (SPSite site = new SPSite("http://servername/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["ListName"];
string values = list["yourColumn"] as string;
string[] choices = null;
if (values != null)
{
choices = values.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
You can try this code for getting choice field value from document library.

Resources