MiFlexible
The MiFlexible component is a Flutter widget that allows for flexible sizing of its child widget within a Row or Column, configurable via JSON.
Overview
MiFlexible extends MiStatelessWidget (defined in MiStatelessWidget.dart), providing a way to control how a child widget occupies space in a flex container. It is particularly useful when combined with MiRow or MiColumn, allowing developers to specify how much space a widget should take relative to its siblings. The flex parameter determines the proportion of available space the child should occupy, enabling responsive layouts.
Component Name: flexible
JSON key: "component": "flexible".
Parameters
| Parameter Key | JSON Value Type | Flutter Type | Description | Default Value | Nullable | Requires Build |
|---|---|---|---|---|---|---|
child | Map | Widget | The child widget to be wrapped in a Flexible widget. This should be a JSON configuration for a widget. | None | No | No |
flex | int | int | The flex factor for the child, determining how much space it occupies relative to other flexible children. A higher value means more space. | 1 | Yes | No |
color | String | Color | The background color of the component. (Inherited from MiStatelessWidget) | Theme default color | Yes | No |
width | num (Number) | double | The width of the component. (Inherited from MiStatelessWidget) | None (Intrinsic width) | Yes | No |
height | num (Number) | double | The height of the component. (Inherited from MiStatelessWidget) | None (Intrinsic height) | Yes | No |
padding | List<num> | EdgeInsets | Padding to be applied around the child. Expects a list of numbers representing padding values. (Inherited from MiStatelessWidget) | None | Yes | No |
margin | List<num> | EdgeInsets | Margin to be applied around the child. Expects a list of numbers representing margin values. (Inherited from MiStatelessWidget) | None | Yes | No |
alignment | String | AlignmentGeometry | How the child should be aligned within its allocated space. Accepts alignment keywords like 'topLeft', 'center', etc. (Inherited from MiStatelessWidget ) | Defaults to topLeft | Yes | No |
Note:
- Inherited Parameters:
color,alignment,width,height,padding, andmarginare inherited parameters fromMiStatelessWidget' and allow for styling and positioning of theMiFlexible. **Refer toMiStatelessWidget.dart` for more details on these inherited parameters.** - Flex Behavior: The
flexparameter is crucial for determining how much space the child occupies relative to otherMiFlexiblecomponents. For example, if one child has aflexof1and another has aflexof2, the second child will take up twice as much space as the first within the same parentRoworColumn. - Helper Classes: The
MiFlexiblecomponent utilizes helper classes likeDoubleHelperandEdgeInsetsHelperfor converting JSON values to the appropriate Flutter types forwidth,height,padding, andmargin.
Example JSON Configurations
Example 1: Flexible Child in a Row
{
"component": "row",
"children": [
{
"component": "flexible",
"flex": 1,
"child": {
"component": "text",
"text": "Child 1",
"color": "blue"
}
},
{
"component": "flexible",
"flex": 2,
"child": {
"component": "text",
"text": "Child 2",
"color": "green"
}
}
]
}
Explanation of Example 1:
component: "row"- Identifies this configuration as aMiRowcomponent, which will contain flexible children.children- An array of child components within theMiRow.- The first child is a
MiFlexiblecomponent with:flex: 1- This child will occupy 1 part of the available space.child- A nestedMiTextcomponent displaying "Child 1" in blue.
- The second child is another
MiFlexiblecomponent with:flex: 2- This child will occupy 2 parts of the available space, effectively taking up twice as much space as the first child.child- A nestedMiTextcomponent displaying "Child 2" in green.
- The first child is a
Example 2: Flexible Child in a Column
{
"component": "column",
"children": [
{
"component": "flexible",
"flex": 3,
"child": {
"component": "text",
"text": "Top Child",
"color": "red"
}
},
{
"component": "flexible",
"flex": 1,
"child": {
"component": "text",
"text": "Bottom Child",
"color": "orange"
}
}
]
}
Explanation of Example 2:
component: "column"- Identifies this configuration as aMiColumncomponent, which will contain flexible children.children- An array of child components within theMiColumn.- The first child is a
MiFlexiblecomponent with:flex: 3- This child will occupy 3 parts of the available vertical space.child- A nestedMiTextcomponent displaying "Top Child" in red.
- The second child is another
MiFlexiblecomponent with:flex: 1- This child will occupy 1 part of the available vertical space, taking up less space than the first child.child- A nestedMiTextcomponent displaying "Bottom Child" in orange.
- The first child is a