{"id":762,"date":"2024-02-05T11:20:04","date_gmt":"2024-02-05T11:20:04","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=762"},"modified":"2024-02-05T11:20:07","modified_gmt":"2024-02-05T11:20:07","slug":"what-is-widgets-in-flutter","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/what-is-widgets-in-flutter\/","title":{"rendered":"What is widgets in Flutter?"},"content":{"rendered":"\n<p><strong>Widgets:&nbsp;<\/strong>Each element on a screen of the Flutter app is a widget. The view of the screen completely depends upon the choice and sequence of the widgets used to build the apps. And the structure of the code of an apps is a tree of widgets.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Category of Widgets:<\/strong><\/h3>\n\n\n\n<p>There are mainly 14 categories in which the flutter widgets are divided. They are mainly segregated on the basis of the functionality they provide in a flutter application.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Accessibility:<\/strong>&nbsp;These are the set of widgets that make a flutter app more easily accessible.<\/li>\n\n\n\n<li><strong>Animation and Motion:<\/strong>&nbsp;These widgets add animation to other widgets.<\/li>\n\n\n\n<li><strong>Assets, Images, and Icons:<\/strong>&nbsp;These widgets take charge of assets such as display images and show icons.<\/li>\n\n\n\n<li><strong>Async:<\/strong>&nbsp;These provide async functionality in the flutter application.<\/li>\n\n\n\n<li><strong>Basics:<\/strong>&nbsp;These are the bundle of widgets that are absolutely necessary for the development of any flutter application.<\/li>\n\n\n\n<li><strong>Cupertino:<\/strong>&nbsp;These are the iOS designed widgets.<\/li>\n\n\n\n<li><strong>Input:<\/strong>&nbsp;This set of widgets provides input functionality in a flutter application.<\/li>\n\n\n\n<li><strong>Interaction Models:<\/strong>&nbsp;These widgets are here to manage touch events and route users to different views in the application.<\/li>\n\n\n\n<li><strong>Layout:<\/strong>&nbsp;This bundle of widgets helps in placing the other widgets on the screen as needed.<\/li>\n\n\n\n<li><strong>Material Components:<\/strong>&nbsp;This is a set of widgets that mainly follow material design by Google.<\/li>\n\n\n\n<li><strong>Painting and effects:<\/strong>&nbsp;This is the set of widgets that apply visual changes to their child widgets without changing their layout or shape.<\/li>\n\n\n\n<li><strong>Scrolling:<\/strong>&nbsp;This provides scrollability of to a set of other widgets that are not scrollable by default.<\/li>\n\n\n\n<li><strong>Styling:<\/strong>&nbsp;This deals with the theme, responsiveness, and sizing of the app.<\/li>\n\n\n\n<li><strong>Text:<\/strong>\u00a0This displays text.<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\"><strong>Types of Widgets:<\/strong><\/h3>\n\n\n\n<p>There are broadly two types of widgets in the flutter:&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Stateless Widget<\/li>\n\n\n\n<li>Stateful Widget<\/li>\n<\/ol>\n\n\n\n<p><img decoding=\"async\" width=\"586\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/20221220080213\/WIDGET.jpg\"><\/p>\n\n\n\n<p>                                                      WIDGET<\/p>\n\n\n\n<p>Description of the widgets used are as follows:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scaffold \u2013 Implements the basic material design visual layout structure.<\/li>\n\n\n\n<li>App-Bar \u2013 To create a bar at the top of the screen.<\/li>\n\n\n\n<li>Text &#8211; To write anything on the screen.<\/li>\n\n\n\n<li>Container \u2013 To contain any widget.<\/li>\n\n\n\n<li>Center \u2013 To provide center alignment to other widgets.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Stateful Widget<\/h3>\n\n\n\n<p>A Stateful Widget has state information. It contains mainly two classes: the\u00a0<strong>state object<\/strong>\u00a0and the\u00a0<strong>widget<\/strong>. It is dynamic because it can change the inner data during the widget lifetime. This widget does not have a\u00a0<strong>build()<\/strong>\u00a0method. It has\u00a0<strong>createState()<\/strong>\u00a0method, which returns a class that extends the Flutters State Class. The examples of the StatefulWidget are Checkbox, Radio, Slider, InkWell, Form, and TextField.<\/p>\n<\/div><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>class Car extends StatefulWidget {  \r\n  const Car({ Key key, this.title }) : super(key: key);   \r\n  \r\n  @override  \r\n  _CarState createState() => _CarState();  \r\n}  \r\n  \r\nclass _CarState extends State&lt;Car> {  \r\n  @override  \r\n  Widget build(BuildContext context) {  \r\n    return Container(  \r\n      color: const Color(0xFEEFE),  \r\n           child: Container(  \r\n            child: Container( \/\/child: Container() )  \r\n        )  \r\n    );  \r\n  }  \r\n}  <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Stateless Widget<\/h3>\n\n\n\n<p>The Stateless Widget does not have any state information. It remains static throughout its lifecycle. The examples of the Stateless Widget are Text, Row, Column, Container, etc.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class MyStatelessCarWidget extends StatelessWidget {  \r\n  const MyStatelessCarWidget ({ Key key }) : super(key: key);  \r\n  \r\n  @override  \r\n  Widget build(BuildContext context) {  \r\n    return Container(color: const Color(0x0xFEEFE));  \r\n  }  \r\n}  <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Widgets:&nbsp;Each element on a screen of the Flutter app is a widget. The view of the screen completely depends upon<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-762","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=762"}],"version-history":[{"count":1,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/762\/revisions"}],"predecessor-version":[{"id":763,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/762\/revisions\/763"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}