{"id":32573,"date":"2024-11-01T09:10:04","date_gmt":"2024-11-01T09:10:04","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32573"},"modified":"2024-11-01T11:54:45","modified_gmt":"2024-11-01T11:54:45","slug":"flutter-course-4-1-what-is-a-widget","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32573\/","title":{"rendered":"Flutter Course, 4.1 What is a Widget?"},"content":{"rendered":"<p><body><\/p>\n<p>\n        In the world of modern mobile application development, Flutter is loved by many developers for its flexibility and performance. The core component of Flutter, the widget, is the basic unit that composes the UI, and understanding it is essential to mastering Flutter. In this article, we will take a deep dive into what a Flutter widget is, its important concepts, and various uses.\n    <\/p>\n<h2>1. Definition of Widgets<\/h2>\n<p>\n        In Flutter, a &#8216;widget&#8217; is the most basic element that composes the user interface. Widgets represent everything displayed on the screen, including text, buttons, images, and layouts. Because Flutter treats everything as a widget, developers can construct every part of the UI as a widget. These widgets can combine with other widgets to create complex UIs.\n    <\/p>\n<h2>2. Types of Widgets<\/h2>\n<h3>2.1 Stateless Widget<\/h3>\n<p>\n        A stateless widget defines a part of the user interface but does not store state. In other words, this widget draws the screen based on immutable data. For example, widgets such as `Text`, `Icon`, and `RaisedButton` fall into this category. Stateless widgets allow for the representation of simple UI elements, and here is an example code for a stateless widget:\n    <\/p>\n<pre><code>import 'package:flutter\/material.dart';\n\nclass MyStatelessWidget extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return Text('Hello, Flutter!');\n  }\n}<\/code><\/pre>\n<h3>2.2 Stateful Widget<\/h3>\n<p>\n        A stateful widget is a widget that allows the user interface to change dynamically. This widget maintains its internal state, allowing the UI to be redrawn based on state changes. For example, if the color changes or the text changes when a button is clicked, a stateful widget can be used. Here is an example code for a stateful widget:\n    <\/p>\n<pre><code>import 'package:flutter\/material.dart';\n\nclass MyStatefulWidget extends StatefulWidget {\n  @override\n  _MyStatefulWidgetState createState() =&gt; _MyStatefulWidgetState();\n}\n\nclass _MyStatefulWidgetState extends State<mystatefulwidget> {\n  int _counter = 0;\n\n  void _incrementCounter() {\n    setState(() {\n      _counter++;\n    });\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return Column(\n      children: [\n        Text('$_counter'),\n        ElevatedButton(\n          onPressed: _incrementCounter,\n          child: Text('Increment'),\n        ),\n      ],\n    );\n  }\n}<\/mystatefulwidget><\/code><\/pre>\n<h2>3. Widget Tree<\/h2>\n<p>\n        Flutter constructs the UI using a tree structure of widgets. All widgets are organized in a parent-child relationship, and widgets can be nested. The widget tree intuitively shows how the UI of a Flutter application is constructed. Parent widgets contain child widgets, allowing for the combination of all elements displayed on the screen.\n    <\/p>\n<h2>4. Reusability of Widgets<\/h2>\n<p>\n        One of the biggest advantages of Flutter widgets is their high reusability. If the user creates frequently used UI components as separate widgets, they can easily be reused elsewhere. For example, if a card UI is created to display user information, it can be made into a widget and reused across multiple screens.\n    <\/p>\n<h2>5. Creating Custom Widgets<\/h2>\n<p>\n        In Flutter, users can create custom widgets in addition to the built-in widgets. The process of creating custom widgets is very useful for building complex UIs tailored to user needs. Here is an example of creating a basic custom widget:\n    <\/p>\n<pre><code>import 'package:flutter\/material.dart';\n\nclass MyCustomWidget extends StatelessWidget {\n  final String title;\n  final Color color;\n\n  MyCustomWidget({required this.title, this.color = Colors.blue});\n\n  @override\n  Widget build(BuildContext context) {\n    return Container(\n      padding: EdgeInsets.all(16.0),\n      color: color,\n      child: Text(\n        title,\n        style: TextStyle(fontSize: 20.0, color: Colors.white),\n      ),\n    );\n  }\n}<\/code><\/pre>\n<h2>6. Layout of Widgets<\/h2>\n<p>\n        Flutter provides various layout widgets to define how UI elements are arranged. Major ones include <code>Column<\/code>, <code>Row<\/code>, <code>Stack<\/code>, and <code>Container<\/code>. Each widget helps to arrange child widgets differently, making it easier to create complex layouts.\n    <\/p>\n<h3>6.1 Column and Row<\/h3>\n<p>\n<code>Column<\/code> and <code>Row<\/code> allow you to arrange child widgets vertically or horizontally. For example, <code>Column<\/code> can be used when creating a list that requires vertical scrolling. Adding a few child widgets will automatically arrange the widgets.\n    <\/p>\n<pre><code>import 'package:flutter\/material.dart';\n\nclass ColumnExample extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return Column(\n      children: [\n        Text('First line'),\n        Text('Second line'),\n        Text('Third line'),\n      ],\n    );\n  }\n}<\/code><\/pre>\n<h3>6.2 Stack<\/h3>\n<p>\n<code>Stack<\/code> widgets are useful for layering child widgets. Each child widget is placed based on its coordinate origin, which provides the advantage of easily creating complex layouts.\n    <\/p>\n<h2>7. Widget Lifecycle in Flutter<\/h2>\n<p>\n        Widgets in Flutter have a lifecycle, managing the processes of creation, update, and destruction. Stateful widgets have methods such as createState(), initState(), didChangeDependencies(), build(), and dispose(). These methods manage the widget&#8217;s lifecycle and update its state.\n    <\/p>\n<h2>8. Conclusion<\/h2>\n<p>\n        In this article, we explored what a widget is in Flutter, the types and uses of widgets, and how to create custom widgets. Flutter&#8217;s widget system provides developers with powerful tools, allowing for the construction of excellent user interfaces. Continuously learning more in-depth content will greatly help in enhancing your Flutter manipulation skills. In the next lesson, we will delve deeper into widgets.\n    <\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the world of modern mobile application development, Flutter is loved by many developers for its flexibility and performance. The core component of Flutter, the widget, is the basic unit that composes the UI, and understanding it is essential to mastering Flutter. In this article, we will take a deep dive into what a Flutter &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32573\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Flutter Course, 4.1 What is a Widget?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[151],"tags":[],"class_list":["post-32573","post","type-post","status-publish","format-standard","hentry","category-flutter-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Flutter Course, 4.1 What is a Widget? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32573\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Flutter Course, 4.1 What is a Widget? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In the world of modern mobile application development, Flutter is loved by many developers for its flexibility and performance. The core component of Flutter, the widget, is the basic unit that composes the UI, and understanding it is essential to mastering Flutter. In this article, we will take a deep dive into what a Flutter &hellip; \ub354 \ubcf4\uae30 &quot;Flutter Course, 4.1 What is a Widget?&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32573\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:10:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:54:45+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32573\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32573\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Flutter Course, 4.1 What is a Widget?\",\"datePublished\":\"2024-11-01T09:10:04+00:00\",\"dateModified\":\"2024-11-01T11:54:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32573\/\"},\"wordCount\":612,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Flutter course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32573\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32573\/\",\"name\":\"Flutter Course, 4.1 What is a Widget? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:10:04+00:00\",\"dateModified\":\"2024-11-01T11:54:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32573\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32573\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32573\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Flutter Course, 4.1 What is a Widget?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Flutter Course, 4.1 What is a Widget? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32573\/","og_locale":"ko_KR","og_type":"article","og_title":"Flutter Course, 4.1 What is a Widget? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In the world of modern mobile application development, Flutter is loved by many developers for its flexibility and performance. The core component of Flutter, the widget, is the basic unit that composes the UI, and understanding it is essential to mastering Flutter. In this article, we will take a deep dive into what a Flutter &hellip; \ub354 \ubcf4\uae30 \"Flutter Course, 4.1 What is a Widget?\"","og_url":"https:\/\/atmokpo.com\/w\/32573\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:10:04+00:00","article_modified_time":"2024-11-01T11:54:45+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32573\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32573\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Flutter Course, 4.1 What is a Widget?","datePublished":"2024-11-01T09:10:04+00:00","dateModified":"2024-11-01T11:54:45+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32573\/"},"wordCount":612,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Flutter course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32573\/","url":"https:\/\/atmokpo.com\/w\/32573\/","name":"Flutter Course, 4.1 What is a Widget? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:10:04+00:00","dateModified":"2024-11-01T11:54:45+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32573\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32573\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32573\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Flutter Course, 4.1 What is a Widget?"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32573"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32573\/revisions"}],"predecessor-version":[{"id":32574,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32573\/revisions\/32574"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}