MiListView
The MiListView component is a Flutter widget for displaying a scrollable list of items.
Overview
MiListView extends MiStatelessWidget, and is used to render a dynamic list of UI components, making it ideal for displaying data-driven content. It supports both vertical lists and dynamic height grids using DynamicHeightGridView (if crossAxisCount is greater than 1).
Component Name: listView
JSON key: "component": "listView"
Parameters
| Parameter Key | JSON Value Type | Flutter Type | Description | Default Value | Nullable | Requires Build |
|---|---|---|---|---|---|---|
listKey | String | List | The key (${key}) that points to the list of data to be displayed. Each item in this list will be used to generate a child component within the list. | [] | Yes | No |
searchable | bool | bool | If true, filters the list based on a "match" key within each list item. Items where "match" is false will be hidden. This requires a search mechanism that updates the 'match' key in your list data. This functionality is enabled by MiSearchField. | false | Yes | No |
spacing | num (Number) | double | The spacing between items in the list. For single-column lists (crossAxisCount == 1), this is the vertical spacing. For grids (crossAxisCount > 1), this is the spacing between both rows and columns. Converted from JSON num to Flutter double using DoubleHelper.get. | 20.0 | Yes | No |
childComponent | Map | Widget | A JSON configuration defining the component to be rendered for each item in the list. This allows you to dynamically generate UI elements based on the data in your list. The childComponent can access the data for the current list item using the widgetArgs scope and keys like ${[index]} (e.g. ${name} instead of ${items[0].name}). | {} | Yes | Yes |
emptyDisplayText | String | String | The text to display when the list is empty (i.e., when listKey resolves to an empty list). | "No items" | Yes | No |
layoutConfig | String | String | A string that specifies how the grid layout should adapt to different screen sizes. It's a series of numbers separated by hyphens (e.g., "3-2-1"), representing the number of columns for extra large, large/expanded and medium/compact screens respectively. "max" sets it to 1 column regardless of the screen size. See ResponsiveBuilder.dart for further details | "3-1" | Yes | No |
color | String | Color | The background color of the list. | Theme default color | Yes | No |
width | num (Number) | double | The width of the list component. | None (Intrinsic width) | Yes | No |
height | num (Number) | double | The height of the list component. | None (Intrinsic height) | Yes | No |
padding | List<num> | EdgeInsets | Padding to be applied around the list. Expects a list of numbers representing padding values (e.g., [left, top, right, bottom] or [horizontal, vertical] or [all]). | None | Yes | No |
margin | List<num> | EdgeInsets | Margin to be applied around the list. Expects a list of numbers representing margin values (e.g., [left, top, right, bottom] or [horizontal, vertical] or [all]). | None | Yes | No |
alignment | String | AlignmentGeometry | How the list should be aligned within its allocated space. Accepts alignment keywords like 'topLeft', 'center', 'bottomRight', etc. Refer to Flutter's Alignment documentation. | Defaults to topLeft | Yes | No |
Note:
- Inherited Parameters:
color,alignment,width,height,padding, andmarginare inherited parameters fromMiStatelessWidgetand allow for styling and positioning of theMiListViewcomponent. - Layout Parameters:
width,height,padding, andmargincontrol the size and spacing of theMiListView. - Responsive Layout: The
layoutConfigparameter, in conjunction with theResponsiveBuilderwidget, allows the number of columns in the grid to adapt to different screen sizes. TheResponsiveBuilderuses breakpoints defined inResponsiveBuilder.dartto determine the currentLayoutType(compact, medium, expanded, large, extraLarge), and thelayoutConfigstring defines the number of columns for each layout type. - Data Binding and Widget Arguments: The
childComponenthas access to the data for the current list item through thewidgetArgs. TheDataUtil.updateWidgetArgsfunction is used to create a newwidgetArgsmap that includes the current item's index, enabling usage of"${name}"instead of"${items[index].name}". Note that"items"must also be declared aslistKeyvalue in theMiListViewconfiguration. - Helper Classes:
DoubleHelper.getandEdgeInsetsHelper.getare used internally to assist in converting JSON values to the correct Flutter types forspacing,paddingandmarginrespectively. - Empty List Handling: If the
listKeyresolves to an empty list, theMiListViewdisplays the text specified in theemptyDisplayTextparameter. - Searchable List: When
searchableis set totrue, each item in theresolvedListmust have a"match"key (boolean). If the"match"key is set tofalse, the list item will not be displayed. This functionality is enabled byMiSearchField.
Example JSON Configurations
Example 1: Basic Vertical List with Text Items
{
"component": "listView",
"listKey": "${names}",
"childComponent": {
"component": "text",
"text": "${name}"
}
}
Explanation of Example 1:
component: "listView"- Identifies this configuration as being for aMiListViewcomponent.listKey: "${names}"- Specifies that the data for the list will be retrieved from the state using the key"names". It is assumed that the state contains a list of names. Refer toKey.childComponent: Defines the component that will be rendered for each item in the list.component: "text"- Specifies that aMiTextcomponent will be used to display each item.text: "${name}"- Sets the text of theMiTextcomponent to the value of the"name"key within each item in thenameslist. This assumes that each item in thenameslist is an object that has a"name"property.
Example 2: Grid with Dynamic Height Cards
{
"component": "listView",
"listKey": "${products}",
"layoutConfig": "2-1",
"spacing": 16,
"childComponent": {
"component": "card",
"width": 200,
"child": {
"component": "column",
"children": [
{
"component": "text",
"text": "${productName}"
},
{
"component": "image",
"url": "${imageUrl}",
"height": 100
}
]
}
}
}
Explanation of Example 2:
component: "listView"- Identifies this configuration as being for aMiListViewcomponent.listKey: "${products}"- Specifies that the data for the list will be retrieved from the state using the key"products". It is assumed that the state contains a list of product objects. Refer toKey.layoutConfig: "2-1"- Configures the grid layout to have 2 columns on larger screens and 1 column on smaller screens. The mEye Framework uses this to manage column counts.spacing: 16- Sets the spacing between the grid items to 16 logical pixels. This numeric JSON value is converted to a FlutterdoubleusingDoubleHelper.get.childComponent: Defines the component that will be rendered for each item in the list.component: "card"- Specifies that aMiCardcomponent will be used to display each item, providing a visual container.width: 200- Sets the width of each card to 200 logical pixels.child: Defines the content of the card using a nestedcolumncomponent.component: "column"- Specifies that aMiColumncomponent will be used to arrange the card's content vertically.children: Defines the child components of the column.component: "text"- Specifies that aMiTextcomponent will be used to display the product name.text: "${productName}"- Sets the text of theMiTextcomponent to the value of the"productName"key within each product object.component: "image"- Specifies that anMiImagecomponent will be used to display the product image.url: "${imageUrl}"- Sets the URL of theMiImagecomponent to the value of the"imageUrl"key within each product object.height: 100- Sets the height of theMiImagecomponent to 100 logical pixels.
Example 3: Searchable List with Filter
{
"component": "column",
"children": [
{
"component": "searchField",
"label": "Search Items",
"listKey": "${items}",
"props": ["name"]
},
{
"component": "listView",
"listKey": "${items}",
"searchable": true,
"childComponent": {
"component": "text",
"text": "${name}"
}
}
]
}
Explanation of Example 3:
component: "column"- Defines theMiColumnthat holds theMiSearchFieldandMiListViewcomponents.component: "searchField"- Configures theMiSearchFieldcomponent.label: "Search Items"- Sets the label for the search field.listKey: "${items}"- Specifies that the search should be performed on the list referenced by the key"items". Refer toKey.props: ["name"]- Indicates that the search should be performed on the"name"property of each item in the"items"list. Refer toKey.
component: "listView"- Configures theMiListViewcomponent.listKey: "${items}"- Specifies that the list should display data from the"items"key.searchable: true- Enables search filtering on the list. It will hide the list items ifresolvedList[index]?['match']isfalse. The list item will be hidden ifresolvedList[index]?['match']isfalse, whichMiSearchFieldis updating.childComponent- Defines the component to render for each list item.component: "text"- Displays the"name"property of each item as text.