{"id":1981,"date":"2022-04-07T06:55:27","date_gmt":"2022-04-07T06:55:27","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1981"},"modified":"2022-04-07T06:55:27","modified_gmt":"2022-04-07T06:55:27","slug":"types-of-widget","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/04\/07\/types-of-widget\/","title":{"rendered":"Types of Widget"},"content":{"rendered":"\n<p>We can split the Flutter widget into two categories:<\/p>\n\n\n\n<ol><li>Visible (Output and Input)<\/li><li>Invisible (Layout and Control)<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Visible widget<\/h3>\n\n\n\n<p>The visible widgets are related to the user input and output data. Some of the important types of this widget are:<\/p>\n\n\n\n<p><strong>Text<\/strong><\/p>\n\n\n\n<p>A Text widget holds some text to display on the screen. We can align the text widget by using&nbsp;<strong>textAlign<\/strong>&nbsp;property, and style property allow the customization of Text that includes font, font weight, font style, letter spacing, color, and many more. We can use it as like below code snippets.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new Text(     \n'Hello, Javatpoint!',     \ntextAlign: TextAlign.center,       \nstyle: new TextStyle(fontWeight: FontWeight.bold),   \n)  <\/code><\/pre>\n\n\n\n<p><strong>Button<\/strong><\/p>\n\n\n\n<p>This widget allows you to perform some action on click. Flutter does not allow you to use the Button widget directly; instead, it uses a type of buttons like a&nbsp;<strong>FlatButton<\/strong>&nbsp;and a&nbsp;<strong>RaisedButton<\/strong>. We can use it as like below code snippets.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/FlatButton Example  \nnew FlatButton(  \n  child: Text(\"Click here\"),  \n  onPressed: () {  \n    \/\/ Do something here  \n  },  \n),  \n  \n\/\/RaisedButton Example  \nnew RaisedButton(  \n  child: Text(\"Click here\"),  \n  elevation: 5.0,  \n  onPressed: () {  \n    \/\/ Do something here  \n  },  \n),  <\/code><\/pre>\n\n\n\n<p>In the above example, the&nbsp;<strong>onPressed<\/strong>&nbsp;property allows us to perform an action when you click the button, and&nbsp;<strong>elevation<\/strong>&nbsp;property is used to change how much it stands out.<\/p>\n\n\n\n<p><strong>Image<\/strong><\/p>\n\n\n\n<p>This widget holds the image which can fetch it from multiple sources like from the asset folder or directly from the URL. It provides many constructors for loading image, which are given below:<\/p>\n\n\n\n<ul><li><strong>Image:<\/strong>&nbsp;It is a generic image loader, which is used by&nbsp;<strong>ImageProvider<\/strong>.<\/li><li><strong>asset:<\/strong>&nbsp;It load image from your project asset folder.<\/li><li><strong>file:<\/strong>&nbsp;It loads images from the system folder.<\/li><li><strong>memory:&nbsp;<\/strong>It load image from memory.<\/li><li><strong>network:<\/strong>&nbsp;It loads images from the network.<\/li><\/ul>\n\n\n\n<p>To add an image in the project, you need first to create an assets folder where you keep your images and then add the below line in&nbsp;<strong>pubspec.yaml<\/strong>&nbsp;file.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<ol><li>assets:&nbsp;&nbsp;<\/li><li class=\"\">&nbsp;&nbsp;&#8211;&nbsp;assets\/&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p>Now, add the following line in the dart file.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<ol><li>Image.asset(&#8216;assets\/computer.png&#8217;)&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p>The complete source code for adding an image is shown below in the&nbsp;<strong>hello world<\/strong>&nbsp;example.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class MyHomePage extends StatelessWidget {  \n  MyHomePage({Key key, this.title}) : super(key: key);  \n  \/\/ This widget is the home page of your application.  \n  final String title;  \n  \n  @override  \n  Widget build(BuildContext context) {  \n    return Scaffold(  \n      appBar: AppBar(  \n        title: Text(this.title),  \n      ),  \n      body: Center(  \n        child: Image.asset('assets\/computer.png'),  \n      ),  \n    );  \n  }  \n}  <\/code><\/pre>\n\n\n\n<p>When you run the app, it will give the following output.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.javatpoint.com\/tutorial\/flutter\/images\/flutter-widgets-1.png\" alt=\"Flutter Widgets\"\/><\/figure>\n\n\n\n<p><strong>Icon<\/strong><\/p>\n\n\n\n<p>This widget acts as a container for storing the Icon in the Flutter. The following code explains it more clearly.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new Icon(  \n  Icons.add,  \n  size: 34.0,  \n)  <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Invisible widget<\/h3>\n\n\n\n<p>The invisible widgets are related to the layout and control of widgets. It provides controlling how the widgets actually behave and how they will look onto the screen. Some of the important types of these widgets are:<\/p>\n\n\n\n<p><strong>Column<\/strong><\/p>\n\n\n\n<p>A column widget is a type of widget that arranges all its children&#8217;s widgets in a vertical alignment. It provides spacing between the widgets by using the&nbsp;<strong>mainAxisAlignment<\/strong>&nbsp;and&nbsp;<strong>crossAxisAlignment<\/strong>&nbsp;properties. In these properties, the main axis is the vertical axis, and the cross axis is the horizontal axis.<\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<p>The below code snippets construct two widget elements vertically.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new Column(  \n  mainAxisAlignment: MainAxisAlignment.center,  \n  children: &lt;Widget&gt;&#91;  \n    new Text(  \n      \"VegElement\",  \n    ),  \n    new Text(  \n      \"Non-vegElement\"  \n    ),  \n  ],  \n),  <\/code><\/pre>\n\n\n\n<p><strong>Row<\/strong><\/p>\n\n\n\n<p>The row widget is similar to the column widget, but it constructs a widget horizontally rather than vertically. Here, the main axis is the horizontal axis, and the cross axis is the vertical axis.<\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<p>The below code snippets construct two widget elements horizontally.<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new Row(  \n  mainAxisAlignment: MainAxisAlignment.spaceEvenly,  \n  children: &lt;Widget&gt;&#91;  \n    new Text(  \n      \"VegElement\",  \n    ),  \n    new Text(  \n      \"Non-vegElement\"  \n    ),  \n  ],  \n),  <\/code><\/pre>\n\n\n\n<p><strong>Center<\/strong><\/p>\n\n\n\n<p>This widget is used to center the child widget, which comes inside it. All the previous examples contain inside the center widget.<\/p>\n\n\n\n<p><strong>Example<\/strong><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Center(  \n  child: new clumn(  \n    mainAxisAlignment: MainAxisAlignment.spaceEvenly,  \n    children: &lt;Widget&gt;&#91;  \n      new Text(  \n        \"VegElement\",  \n      ),  \n      new Text(  \n        \"Non-vegElement\"  \n      ),  \n    ],  \n  ),  \n),  <\/code><\/pre>\n\n\n\n<p><strong>Padding<\/strong><\/p>\n\n\n\n<p>This widget wraps other widgets to give them padding in specified directions. You can also provide padding in all directions. We can understand it from the below example that gives the text widget padding of 6.0 in all directions.<\/p>\n\n\n\n<p><strong>Example <\/strong>:<a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/flutter-widgets#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Padding(  \n  padding: const EdgeInsets.all(6.0),  \n  child: new Text(  \n    \"Element 1\",  \n  ),  \n),  <\/code><\/pre>\n\n\n\n<p><strong>Scaffold<\/strong><\/p>\n\n\n\n<p>This widget provides a framework that allows you to add common material design elements like AppBar, Floating Action Buttons, Drawers, etc.<\/p>\n\n\n\n<p><strong>Stack<\/strong><\/p>\n\n\n\n<p>It is an essential widget, which is mainly used for&nbsp;<strong>overlapping<\/strong>&nbsp;a widget, such as a button on a background gradient.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We can split the Flutter widget into two categories: Visible (Output and Input) Invisible (Layout and Control) Visible widget The visible widgets are related to the user input and output data. Some of the important types of this widget are: Text A Text widget holds some text to display on the screen. We can align [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[675],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1981"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1981"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1981\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}