flutter : How To build a grid view with expanded text child - list

I need to Build this UI Using Flutter, List or (Grid view) of categories which every category has title as text and this texts is different lengths(maybe 4 letters and maybe 15 ).
any suggestions??
Note : data will fetched from API endpoint

You can use Wrap instead of GridView.
Wrap(
children: result
.map(
(e) => Chip(label: Text(e)),
)
.toList()),
More about Wrap and Chip.

Related

Flutter Animated Switcher with List of Widgets

I have a CustomScrollView with several children. One children should always be displayed but the other ones should be displayed depending on a condition:
CustomScrollView(
controller: articleState.scrollController,
slivers: [
ArticleDetailPageHeader(widget.articleShort), // <- should always be displayed
...condition
? _buildShimmerWidgets() // returns List<Widget>
: _buildArticleWidgets(context, articleState), // ยดยด
],
)
This is working. But I would like to use a AnimatedSwitcher so the UI looks a bit smoother.
I look into AnimatedSwitcher and it takes a child of the type Widget. Now that is the Problem! I have a List<Widget. Is there any workaround for this?
I hope my problem is clear, let me know if you need any more info!
Try to use a Column as the child for the AnimatedSwitcher and then pass the List<Widget> as children for the Column.

How to create a list of Network images in Flutter

I use "Carousel Pro" package to implement a carousel in my screen, in this Carousel class it need a list of images,
The syntax for Carousel class is
Carousel(
images: [
NetworkImage('https://cdn-images-1.medium.com/max/2000/1*GqdzzfB_BHorv7V2NV7Jgg.jpeg'),
NetworkImage('https://cdn-images-1.medium.com/max/2000/1*wnIEgP1gNMrK5gZU7QS0-A.jpeg'),
ExactAssetImage("assets/images/LaunchImage.jpg")
],
)
i had a list of network image urls which is parsed from the json data,
How ca i add the url list to the child 'images' of Carousel class.
It's easy just create a NetworkImage List and use it directly like this:
List<NetworkImage> images = List<NetworkImage>();
images.add(NetworkImage('url1');
images.add(NetworkImage('url2');
And in your Carousel should be like this
Carousel(
images: images
)
I hope this was helpful
This best way would be to create a list/array of your network images and either list them as such
List imageList = (http://cdn-images-1, http://cdn-images-2, http://cdn-images-3,)
Carousel(
images: [
NetworkImage(imageList[0]),
NetworkImage(imageList[1]),
NetworkImage(imageList[2]),
ExactAssetImage("assets/images/LaunchImage.jpg")
],
)
Or, use a ListView.builder to iterate through your list and use the index <- this would be ideal if you have a list that varies or may change during a view state.
ListView _buildList(context) {
return ListView.builder(
itemCount: imageList.length,
itemBuilder: (context, int) {
return Carousel(
images: [
NetworkImage(imageList[int]),
ExactAssetImage("assets/images/LaunchImage.jpg")
],
);
},
);
}
You can use map to make a list of NetworkImage:
images: imageURLs.map((String url) {
return new NetworkImage(url));
}).toList(),
with imageURLs is the List url of your images
First of all create a List of NetworkImage:
List<NetworkImage> productImage = [];
Then you'll need to create a function that'll enable you to add the List of Strings of Network images to your productImage List.
static List<NetworkImage> productAssets(List<String> images) {
List<NetworkImage> asset = List<NetworkImage>();
for (String item in images) {
asset.add(NetworkImage(item));
}
return asset;
}
The function above takes the List of String of images and returns a List of Network images.
What you need to do now is to use the List (productAssets) to parse in the String of Network images URLs to add them to your Carousel images.
productImages: productAssets(['http://www.image1.com', 'http://www.image2.com']);
All you have to do now is to parse the productImages in your Carousel Widget
Carousel (
images: productAssets,
)

Webix layout as template

I'm new to Webix and trying to create a list or dataview where users can add and remove itens. (font files this time)
For such i defined one "add" button and one list where previously added items are displayed.
My plan was to put an label and a exclude button into each item of the list with the components Webix already provides but to my surprize the template property of data components aparentily can't be definied with ui objects itself.
There is some way to do it?
Somethink like it:
webix.ui({ id:'stage', rows:[
{ view:"button", type:"icon", icon:"plus", label:"Add Font", autowidth:true, click:AddFont },
{ view:"dataview", id:"fnt_list", data:fonts(), width:300,
type:{ width:300, height:150, template:function(fnt)
{
return webix.ui({cols:[
{view:"label", align:"left", label:fnt.fileName },
{view:"button", type:"icon", icon:"trash", label:"Exclude", align:"right", autowidth:true }
]});
}}
}]});
I know it can be made with the layout component alone but i really would like to do it with one of the data components because of the paging feature they have.
While it possible to create a separate instance of webix UI for each row, it is overkill for your task, just use HTML markup in the template. Something like next
{ view:"dataview", css:"fonts", id:"fnt_list", data:fonts, width:300,
type:{
width:300, height:150,
template:"#fileName# <i class='fa fa-trash-o'></i>"
},
working snippet - https://snippet.webix.com/dvbdt6st
If you still want to have real UI widgets inside of dataview items, check
https://docs.webix.com/desktop__data_layout.html
and
https://docs.webix.com/desktop__active_content.html

Sitecore Speak UI : How to manipulate column value of List Control before displaying in list .

I am working in speak UI . I have list of items to display in list . But before that i have to check one column value and need to manipulate this value with a Icon to display . How can I implement this change in SpeakUI . Please help
Simple option:
If the data you receive is directly relateable to the icon you want to display:
Set your DataSource on your ListControl to a ListControl Parameters item with your ColumnField items underneath (as outlined in Sitecore doco or other blogs). In the HTMLTemplate field for your column, you can use the value as the source of an image or CSS class with background image style.
<img src="{{YourField}}" />
or
<span class="{{YourField}}"></span>
where your span class styles your icon.
More complex but customisable:
I'm not sure which datasource you are using, but I am a fan of the JsonDataSource by Anders Laub as it's very simple to use and customise (you only need to add 2 small files).
To your SPEAK renderings you add your JsonDataSource, and ListControl with Items property: {Binding JsonDataSource.Json} (and DataSource as required)
Then in the javascript for your page (defined in your PageCode rendering) you can add items to this datasource and customise as required:
jQuery.ajax({
type: "GET",
dataType: "json",
url: "/yourApiCall" + params,
cache: false,
success: function (data) {
var total = 0;
for (var i = 0; i < data.YourItems.length; i++) {
app.JsonDataSource.add({
Col1: data.YourItems[i][0],
Col2: data.YourItems[i][1],
Col3: data.YourItems[i][2]
});
}
},
Where Col1, Col2, and Col3 are the names of your columns, and YourItems is the array of items you are receiving from your ajax call.

Orchard container without creating list tags

I am using Orchard to create a table-like layout. I have defined two content types: 'Row' and 'Column'. To allow items of the type Column to be added to a Row I added the 'Container' part to the Row and 'Containable' to the Column.
All works fine, the columns show up in the row they were put in, however Orchard renders list tags around my columns which mess up my layout. Is it possible to prevent these list tags from being rendered? I checked out the source of ContainerPartDriver.cs but the 'listShape' seems to be baked in, however I hope someone can prove me wrong.
For now I am retrieving the container items and displaying each one in the view itself.
#{
var contentManager = WorkContext.Resolve<IContentManager>(); ;
var container = (ContentItem)Model.ContentItem;
var query = contentManager
.Query(VersionOptions.Published)
.Join<CommonPartRecord>().Where(x => x.Container.Id == container.Id)
.Join<ContainablePartRecord>().OrderByDescending(x => x.Position);
}
#foreach (var item in query.List())
{
#Display(contentManager.BuildDisplay(item, "Detail"));
}