An Introduction to Flutter Material Widgets

 
In this post you can learn flutter material widgets. Each material widget is explained briefly in this post. Flutter Material Widgets create a consistent user experience across apps and platforms.

As the Material Design system evolves, these flutter material widgets are updated to ensure consistent pixel-perfect implementation, adhering to Google’s front-end development standards. You can also check out flutter tutorials.

Navigation Widgets

MaterialApp

A feature widget that wraps multiple widgets that are typically required for content design applications. It builds on a WidgetApp by adding content-design specific functionality, such as AnimatedTheme and GridPaper. MaterialApp configures the top-level navigator to search for routes in the following order:

  •   / For the passage, the property of the house, if non-zero, is used.
  •   Otherwise, the route table is used if it has an entry for the route.
  •   Otherwise, onGenerateRoute is called, if provided. This should return a non-zero value for any valid route that has not been controlled by home and routes.
  •   In the end if all else fails then unintentional is called.

If a navigator is created, at least one of these options must handle the option / route, as it is used when an invalid initialization is specified at startup.  

WidgetsApp

A feature class that wraps multiple widgets that are usually required for an application. One of the primary roles provided by WidgetsApp is binding the system back button to pop the navigator or quit the application.

Scaffold 

The basic material design visual layout implements the structure. This class provides APIs to show drawers, snack bars, and lower sheets. To display a snackbar or consecutive bottom sheet, get ScaffoldState for the current BuildContext via Scaffold.of and use the ScaffoldState.showSnackBar and ScaffoldState .showBottomSheet functions.  

Appbar

An app bar contains a toolbar and possibly other widgets, such as TabBar and FlexibleSpaceBar. App bars typically expose one or more common actions with IconButtons followed optionally by a popupmenubutton for a less common operation (sometimes called the “overflow menu”). The app bar is commonly used in the Scaffold.appBar property, which places the app bar as a widget with a fixed height at the top of the screen. For a scrollable app bar, use SliverAppBar, which embeds AppBar into a sliver for use in a CustomScrollView. When not used as Scaffold.appBar, or when wrapped in a hero, place the app bar in MediaQuery to take care of padding around the contents of the app bar if the padding is not handled by Scaffold Will go. The AppBar toolbar displays widgets, leads, titles, and actions, from bottom to top (if any). The bottom is usually used for a TabBar. If a Flexibility widget is specified, it stands behind the toolbar and the bottom widget.

SliverAppBar

A content design app bar that integrates with a CustomScrollView. An app bar contains a toolbar and possibly other widgets, such as TabBar and FlexibleSpaceBar. App bars typically expose one or more common actions with IconButton s followed by a popupmenubutton for optionally less common operations.   The Sliver app bar is commonly used as the first child of a CustomScrollView, which integrates the app bar with the scroll view, so that it can vary in height according to the scroll offset and above other content in the scroll view Could swim For an app bar with a fixed height at the top of the screen, see AppBar, which is used in the Scaffold.appBar slot.  

Drawer

A content design panel that slides horizontally from the edge of a scaffold to show navigation links in an application. Drawers are commonly used with the Scaffold.drawer property. The child of the drawer is usually a list view whose first child is a drawer that displays status information about the current user. The remaining drawer children are often constructed with ListTiles, often concluding with an AbsoluteListTile.

TabBar

A content design widget that displays a horizontal row of tabs. Usually created as an AppBar.bottom part of an AppBar and in conjunction with a TabBarView. If a TabController is not provided, a DefaultTabController ancestor must be provided instead. The tabController.length of the tab controller must be equal to the length of the tab list and the length of the tabBarView.children list. To be a content widget requires one of its ancestors. If it is set in the current context, then TabBarTheme uses the values ​​from it.  

TabBarView

A page view that displays widgets that match the currently selected tab. This widget is typically used in conjunction with a TabBar.   If a TabController is not provided, a DefaultTabController must be the ancestor. The TabController.length of the tab controller must be equal to the length of the list of children and the length of the TabBar.tabs list.  

BottomNavigationBar

A content widget that is displayed at the bottom of an app to select between a small number of views, typically between three and five. The bottom navigation bar contains several items in the form of text labels, icons, or both, placed above a piece of content. It provides quick navigation between top-level views of the app. For larger screens, side navigation may be a better fit.

A lower navigation bar is typically used in conjunction with a scaffold, where it is provided as a Scaffold.bottomNavigationBar argument. The type of navigation bar below changes how its items are displayed. If not specified, it is automatically set to BottamNavigationBarType.fixed when less than four items, and BottamNavigationBarType.shifting otherwise. BottamNavigationBarType.fixed, default when less than four items. If it is non-null, the selected item is provided with the selected ItemColor, otherwise the Theme’s ThemeData.primaryColor is used. If the backgroundColor is null, the background color of the navigation bar defines the material background color in ThemeData.canvasColor (essentially opaque white).

BottamNavigationBarType.shifting, default if there are four or more items. If the selected ItemColor is null, then all items are given in white. The background color of the navigation bar is the same as the BottamNavigationBarItem.backgroundColor of the selected item. In this case it is assumed that each item will have a different background color and the background color will contrast well with white.

Button Widgets

ButtonBar

An end-lined row of buttons, lying in a column when there is not enough horizontal space. Place the button horizontally according to the buttonpad. The children are placed in a row with the menaxis element. When Directionality is TextDirection.ltr, the children in the button bar have the correct justification and the last child becomes the most correct child. When the Directionality TextDirection.rtl children are left justified and the last child becomes the eldest child.

If the width of the button bar exceeds the maximum width constraint on the widget, it aligns its buttons in a column. The main difference here is that the MainAxisAlignment would then be treated as a cross-axis / horizontal alignment. For example, if the button overflow and ButtonBar.alignment were set to MainAxisAligment.start, the buttons would align with the horizontal start of the button bar.

ButtonBar can be configured with ButtonBarTheme. For any null property on ButtonBar, the surrounding ButtonBarTheme property will be used instead. If the ButtonBarTheme property is null, the property will default to the value described in the field documentation below.

The children are wrapped in a ButtonTheme, which is a copy of the surrounding ButtonTheme, with the ButtonBar properties overridden by the ButtonBar properties specified above. These properties include ButtonTextTheme, buttonMinWidth, buttonHeight, buttonPadding, and buttonAlignedDropdown.  

DropdownButton

A Material Design button for selection from the list of materials. A dropdown button allows the user to select from several items. The button shows the currently selected item as well as an arrow that opens a menu to select another item.

Type T is the type of value that represents each dropdown item. All entries in a given menu must represent values ​​with corresponding types. Typically, an anum is used. Each DropdownMenuItem item must be special with the same type of argument.

  The onChanged callback must update a state variable that defines the value of the dropdown. It should also call State.setState to rebuild the dropdown with the new value.  

FlatButton

A flat button is a (zero height) label displayed on a content widget that responds to touch by filling with color. 

Use the flat button on the toolbar, in the dialog, or inline with other content but offset with padding from that material so that the appearance of the button is clear. Intentional flat buttons do not have visible borders and therefore must depend on their position relative to other content for reference. In dialogue and cards, they should be grouped into one of the bottom corners. Avoid using flat buttons where they will mix with other ingredients, for example between lists.

The material design flat button has an all-cap label, some internal padding, and some defined dimensions. Part of your application should be interactive, with ink splatter, instead of being committed to these stylistic options, consider using inkwell.

If onPressed and onLongPress callbacks are null, this button will be disabled, will not respond to touch, and will be colored as specified by the disable border property instead of the color property. If you are trying to change the color of the button and have no effect, check that you are going through a non-on honor handler.

  Flat buttons have a minimum size of 88.0 up to 36.0 which can be overridden with ButtonTheme.  

FloatingAction

The floating action button is a circular icon button that hovers over the content to promote the primary action in the application. The floating action button is commonly used in the Scaffold.floatingActionButton field.

Most single floating actions on each screen use buttons. The floating action button should be used for positive actions such as “create”, “share”, or “navigate”. (If more than one floating action button is used within a route, make sure that each button has a unique hero tag, otherwise an exception will be thrown.)

  If the onPressed callback is null, the button will be disabled and will not respond to touch. It is highly discouraged to disable the floating action button because there is no indication to the user that the button is disabled. Disable the Temporary Action button, consider changing the background color.  

ButtonIcon

An icon button is a picture printed on a content widget that responds to touch by filling it with color (ink). Icon buttons are commonly used in the AppBar.actions field, but they can also be used in many other places.

If the onPressed callback is null, the button will be disabled and will not respond to touch. To be a content widget requires one of its ancestors.

  The hit area of ​​an icon button, if possible, is at least kMinInteractiveDimension pixels in size, regardless of the actual iconSize, to meet the touch target size requirements in the material design specification. The alignment controls how the icon is positioned within the hit area.  

ButtonOutline

Similar to a flatbutton with a thin gray round rectangle border. The outline of the outline button is defined by shape and its form is defined by borderside, deselctedBorderColor and highlightedBorderColor. By default the border is a pixel wide gray circular rectangle that does not change when the button is pressed or disabled. The background of the button is transparent by default.

If onPressed or onLongPress callbacks are null, the button will be disabled and disabled by default will be like a flat button in a flat.

The highlight of the button, which defines the size of the drop shadow when the button is pressed, is 0.0 (no shadow) by default. If the highlight elevation is given a value greater than 0.0, the button becomes a cross between RaisedButton and FlatButton: a bordered button whose height increases and whose background becomes opaque when the button is pressed.

If you want an ink-splash effect for tap, but don’t want to use a button, consider using inkwell directly. The Outline button has a minimum size of 88.0 to 36.0 which can be overridden with ButtonTheme.  

ButtonPopupMenu

A menu is suppressed when the menu is rejected and the menu is rejected because an item was selected. The value given to OnSelected is the value of the selected menu item.

The child or one of the icons can be provided, but not both. If the icon is provided, the PopupMenuButton behaves like an IconButton.

  If both are zero, a standard overflow icon is created (depending on the platform).  

ButtonRaisedButton

A raised button is based on a content widget whose material increases as soon as you press the button.

Use raised buttons to add dimensions otherwise in long busy lists of materials, or in wide spaces, such as a mostly flat layout. Avoid using already raised content such as dialogs or raised buttons on cards.If onPressed and onLongPress callbacks are null, the button will be disabled and disabled by default will be like a flat button in flat. If you are trying to change the color of the button and have no effect, check that you are going through a non-nailed onpressed or onlongpress callback.

If you want an ink-splash effect for tap, but don’t want to use a button, consider using inkwell directly. The minimum size of the raised buttons is 88.0 36.0 which can be overridden with the buttontheme.

Input and Selection Widgets

Checkbox

The checkbox itself does not maintain any status. Instead, when the status of the checkbox changes, the widget calls the on-call callback. Most widgets that use the checkbox will listen for the onChanged callback and recreate the checkbox with a new value to update the view format of the checkbox.

The checkbox can optionally display three values ​​- true, false and null – if the tristate is true. A dash is displayed when the value is zero. By default the tristate is false and the value of the checkbox must be true or false.  

Date & Time Pickers

A material design shows a dialog containing the date picker. The returned future resolves the date chosen by the user when the user closes the dialog. If the user cancels the dialog, the null is returned.

An optional selectableDayPredicate function can be passed to select one day to enable selectableDayPredicate. If provided, only days that are correct for selectableDayPredicate will be selectable.

An optional initialDatePickerMode argument can be used to display the date picker initially in year or month + day picker mode. It defaults to month + day, and should not be null.

An optional locale argument can be used to set the locale for the date picker. This is an omission for the ambient location provided by localizations.

An optional textDirection argument can be used to set the text direction (RTL or LTR) for the date picker. This is an omission of ambient text direction provided by directionality. If both locale and textDirection are not null, then textDirection overrides the direction selected for locale.

The context and useRootNavigator arguments are passed to show the dialog, for which the documentation discusses how it is used. The builder parameter can be used to add hereditary widgets such as themes to dialog widgets.

Radio

Used to choose between a number of mutually exclusive values. When a radio button is selected in a group, the other radio buttons in the group are saved from being selected. Value Type T, type parameter of the radio class. Enum is commonly used for this purpose. The radio button itself does not maintain any state. Instead, the selection of the radio invokes the onchanged callback, passing the value as a parameter. If GroupValue and Price match, this radio will be selected. Most widgets will be onchanged by calling State.setState to update the group value of the radio button.

Slider

Used to select from a range of values. A slider can be used to select from a continuous or discrete set of values. The default is to use a continuous range from minimum to maximum. To use discrete values, use a non-zero value for the partitions, indicating the number of discrete intervals. For example, if the minimum is 0.0 and the maximum is 50.0 and the division is 5, the slider may take discrete values ​​at 0.0, 10.0, 20.0, 30.0, 40.0 and 50.0. The conditions for parts of a slider are:

  • “Thumb”, which is a shape that slides horizontally when the user draws it.
  • “Track”, which is the line in which the slider slides with the thumb.
  • “Value Indicator”, which is a shape that is dragging the thumb to indicate the value selected by the user.
  • The “active” side of the slider is the side between the thumb and the minimum value.
  • The “passive” side of the slider is the side between the thumb and the maximum value.
  • The slider will be deactivated if onChanged is null or if there is a limit given by min then the maximum is blank (if min is equal to the maximum).

The slider widget itself does not maintain any state. Instead, when the position of the slider changes, the widget calls the on-call callback. Most widgets that use a slider will listen for an onChanged callback and rebuild the slider with a new value to update the slider’s visual appearance. To know when the value starts changing, or when it is changed, set the optional callback to On. By default, a slider will be as wide as possible, centered vertically. When unbound constraints are given, it will attempt to widen the track 144 pixels (with margins on each side) and shrink vertically.  

Switch

Used to turn on / off state of single setting. The switch itself does not maintain any state. Instead, when the switch status changes, the widget calls the On Calling callback. Most of the widgets using the switch will listen for onChanged callbacks and rebuild the switch with a new value to update the view format of the switch. If the onChanged callback is null, the switch will be disabled (it will not respond to input). The thumb and track of a default switch are presented in shades of gray by default. The default presence of a disabled switch can be overridden with inactiveThumbColor and inactiveTrackColor.

TextField

A text field allows the user to enter text, either with a hardware keyboard or with an onscreen keyboard. Whenever the user changes the text in the field, the text field calls the On Calling callback. If the user indicates that they have been typed in the field (e.g., pressing a button on a soft keyboard), the text field says an onSubmitted callback. To control the text displayed in the text field, use a controller. For example, to set the initial value of a text field, use a controller that already contains some text. The controller can also control the selection and composition area (and to see changes in the text, selection, and composition area). By default, a text field has a decoration that draws a divider below the text field. You can use the property of decoration to control the decoration, for example by adding a label or an icon. If you set the decor property to zero, the decor will be removed entirely, including additional padding offered by the decor to save space for labels. If the decoration is non-null (which is the default), the text field requires a content widget from one of its ancestors. To integrate TextField into forms with other FormField widgets, consider using TextFormField. Remember to dispose of TextEditingController when it is not needed. This will ensure that we release any resources used by the object.

Dialogs Widgets

AlertDialog

The alert dialog informs the user about situations that require acknowledgment. An alert dialog has an optional title and an optional list of actions. The title is displayed above the content and the actions are displayed below the content.

If the content is too large to fit vertically on the screen, the dialog will display titles and functions and allow the content to overflow, which is rarely desired. To avoid overflow, consider using a scrolling widget for content, such as a SingleChildScrollView. (However, keep in mind that as AlertDialog tries to shape itself using its child’s internal dimensions, widgets such as ListView, GridView and CustomScrollView, which use lazy viewers, won’t work if. If this is the problem, consider using direct dialog.)  

BottomSheet

There are two types of bottom sheets in material design:

A continuous bottom sheet shows information that complements the primary content of the app. When the user interacts with other parts of the app, a continuous bottom sheet appears. Successive lower sheets can be created and displayed with the ScaffoldState.showBottomSheet function or by specifying the Scaffold.bottomSheet constructor parameter.

Modal. A modal bottom sheet is a menu or a choice of a dialog and prevents the user from interacting with the rest of the app. The modal bottom sheet can be created and displayed with the showModalBottomSheet function.

  BottomSheet widgets are rarely used directly. Instead, ScaffoldState.showBottomSheet or Scaffold.bottomSheet, and prefer to create a continuous bottom sheet with a modal lower sheet with showModalBottomSheet.  

ExpansionPanel

A content expansion panel. It has a header and a body and can either be expanded or collapsed. The body of the panel is visible only when expanded.

  The extension panel is intended to be used as children only for the ExtensionPanelList.  

SimpleDialog

A simple dialog gives the user a choice between several options. A simple dialog has an optional title that is displayed above the options.

The option is usually represented using the SimpleDialogOption widget. If other widgets are used, see Contentpadding for notes regarding conventions to achieve the required spacing by the content design.

SnackBar

A light message with an optional action that briefly displays at the bottom of the screen. To display the snack bar, call Scaffold.of (context) .showSnackBar (), which gives an example of the snackbar that describes the message.   To find out how long the snackbar appears, specify a duration. A SnackBar will not time with an action when TalkBack or VoiceOver is enabled. This is controlled by AccessibilityFeatures.accessibleNavigation.

Information Display Widgets

Card

A Material Design Card. A card has a slightly rounded corner and a shadow. A card is a sheet of material used to represent some related information, for example an album, a geographic location, a meal, contact details, etc.

Chip

Chips are compact elements that represent an attribute, text, unit, or action. Supplying non-null running callbacks would cause a button to be included to remove the chip. Its ancestors should include Material, MediaQuery, Directionality and Materialocalizations. All these widgets are usually provided by MaterialApp and Scaffold. Label and clipbearer arguments must not be null.

CircularProgressIndicator

A material design circular progress indicator, which indicates that the application is busy. A widget that shows progress with a circle. There are two types of circular progress indicators: To decide Determine the progress indicator that each point has a specific value in time, and the value should increase monotonically from 0.05 to 1.0 at which time the indicator is completed. To create a defined progress indicator, use a non-zero value between 0.0 and 1.0. To unsure Indeterminate progress indicators do not have a specific value at each point and instead indicate that progress is being made without indicating how much. To create an indefinite progress indicator, use a null value.

DataTable

Displaying data in a table is expensive, because all data needs to be measured twice in order to lay the table, once to negotiate the dimensions used for each column, and once to actually negotiate the results. For laying the table while viewing. For this reason, if you have a lot of data (say, a dozen columns with more than a dozen rows, although the exact limits depend on the target device), then it is suggested that you use a PaginatedDataTable Which automatically splits the data into several pages.

GridView

The main axis direction of the grid is the direction in which it scrolls (scrolldirection). The most commonly used grid layouts are GridView.count, which creates a layout with a fixed number of tiles in the cross axis, and GridView.extent, which creates a layout with tiles that have the maximum cross-axis limit. A custom SliverGridDelegate can produce an arbitrary 2D arrangement of children, including arrangements that are untranslated or overlapped. To create a grid with a large (or infinite) number of children, use a grid with a SliverGridDelegateWithFixedCrossAxisCount or a SliverGridDelegateWithMaxCrossAxisExtent for gridDelegate.

LinearProgressIndicator

A material design linear progress indicator, also known as a progress bar. A widget that shows progress along a line. There are two types of linear progress indicators: To decide Determine the progress indicator that each point has a specific value in time, and the value should increase monotonically from 0.05 to 1.0 at which time the indicator is completed. To create a defined progress indicator, use a non-zero value between 0.0 and 1.0. To unsure Indeterminate progress indicators do not have a specific value at each point and instead indicate that progress is being made without indicating how much. To create an indefinite progress indicator, use a null value.

Tooltip

Tooltips provide text labels that help explain the function of a button or other user interface action. To long-press the widget (or when the user performs some other appropriate action) wrap the button in a tooltip widget. Many widgets, such as IconButton, FloatingActionButton, and PopupMenuButton have a tooltip property that, when non-zero, causes the widget to include a tooltip in its creation. Tooltips improve the accessibility of widget widgets, proving a textual representation of the widget, which can be asserted by a screen reader.    

Leave a Reply