> For the complete documentation index, see [llms.txt](https://ecm-pmdm-flutter.gitbook.io/1.-introduccion-a-flutter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ecm-pmdm-flutter.gitbook.io/1.-introduccion-a-flutter/4.-conceptos-fundamentales-en-flutter/widgets.md).

# Widgets

{% hint style="info" %}
**Catálogo** de widgets:  <https://docs.flutter.dev/development/ui/widgets>

Ejemplo: <https://docs.flutter.dev/development/ui/interactive>
{% endhint %}

En Flutter los **elementos** de la **UI** son objetos del tipo **Widget**  (casi todo en una aplicación Flutter son widgets)

<mark style="color:purple;">El</mark> <mark style="color:purple;"></mark><mark style="color:purple;">**widget**</mark> <mark style="color:purple;">**describe**</mark> <mark style="color:purple;">**cómo**</mark> <mark style="color:purple;"></mark><mark style="color:purple;">debe</mark> <mark style="color:purple;"></mark><mark style="color:purple;">**mostrarse**</mark> <mark style="color:purple;"></mark><mark style="color:purple;">el</mark> <mark style="color:purple;"></mark><mark style="color:purple;">**elemento**</mark> <mark style="color:purple;">**UI**</mark> <mark style="color:purple;"></mark><mark style="color:purple;">en</mark> <mark style="color:purple;"></mark><mark style="color:purple;">**pantalla**</mark> <mark style="color:purple;"></mark><mark style="color:purple;">teniendo en cuenta la actual</mark> <mark style="color:green;">**configuración**</mark> <mark style="color:purple;">y el</mark> <mark style="color:green;">**estado**</mark><mark style="color:purple;">.</mark>

> <mark style="color:green;">La "</mark><mark style="color:green;">**configuración"**</mark> <mark style="color:green;"></mark><mark style="color:green;">son</mark> <mark style="color:green;">los parámetros que se le pasan a un widget cuando se crea (por ejemplo, el color del texto para un widget Text o el child de un widget Center).  Esta información es</mark> <mark style="color:green;"></mark><mark style="color:green;">**inmutable**</mark> <mark style="color:green;"></mark><mark style="color:green;">y el propio widget no puede cambiar.</mark>
>
> <mark style="color:green;">El "</mark><mark style="color:green;">**estado**</mark><mark style="color:green;">" es la información que tu aplicación necesita recordar en un momento dado y que puede cambiar, (</mark><mark style="color:green;">**mutable**</mark><mark style="color:green;">) y puede afectar a cómo se visualizan los widgets. Por ejemplo:  el valor actual de un contador,  si un checkbox está marcado o no, el texto que un usuario ha escrito en un campo de texto, una lista de productos descargada de internet, etc.</mark>

Flutter proporciona un **catálogo** muy completo de **widgets** **standard** de todo tipo: botones, listas, pilas, ....&#x20;

Los widgets se pueden **personalizar** utilizando las propiedades y pueden contener uno o más hijos.  Así, por ejemplo, si queremos un widget que muestre un texto personalizado, crearemos un nuevo widget que se **componga** de Text.

* Flutter prefiere la **composición** sobre la herencia.  Toda app Flutter se compone de ventanas que a su vez se componen de widgets:  **app -> screens -> widgets**

Los widgets están diseñados para ser **inmutables** (unchangeable) lo que ayuda a mantener la UI muy ligera.  <mark style="color:orange;">Para</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**actualizar**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">la</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**UI**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">se deberá</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**crear**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">una</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**nueva**</mark> <mark style="color:orange;">**instancia**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">con los cambios:</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**Flutter**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">se encarga de</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**reutilizar**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">y</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**recyclar**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">de forma</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**eficiente**</mark> <mark style="color:orange;"></mark><mark style="color:orange;">los</mark> <mark style="color:orange;"></mark><mark style="color:orange;">**widgets**</mark>.

### Tipos de Widgets

Nuestras aplicaciones se comprondrán de widgets que son **subclase** de:

* **`StatelessWidget`**: Widgets que solo dependen para su configuración de la información **estática** que contienen (por ejemplo, una imagen estática en un image view, o un texto de título).
* **`StatefulWidget`**: Widgets que necesitan mantener información de **estado** dinámica.  Lo consiguen utilizando un objeto del tipo `State`.

Ambos tipos de **widgets**, `stateless` y `stateful`  **se redibujan cada vez que el framework de Flutter se lo pide, por tanto,&#x20;**<mark style="color:blue;">**todo widget deberá implementar el método**</mark><mark style="color:blue;">**&#x20;**</mark><mark style="color:blue;">**`build()`**</mark> (que describe  el widget a partir de otros widgets, configurando así el **árbol de widgets**)

La **diferencia** entre ambos tipos de widgets es que los widgets **`stateful`** delegan su configuración a un objeto **`State`** y se pueden **actualizar** a **petición** en tiempo de ejecución.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ecm-pmdm-flutter.gitbook.io/1.-introduccion-a-flutter/4.-conceptos-fundamentales-en-flutter/widgets.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
