Skip to main content

3 posts tagged with "tips"

View All Tags

Equality in Flutter and Dart with Equatable

· 3 min read
Yayo Arellano
Software Engineer

In this article, we will review how equality works in Dart and Flutter and how the Equatable package can help us to avoid writing a lot of boilerplate code.

We already know that If we want to compare two variables, we can use the == operator. For example, if we want to compare two strings, the code is:

  final car1 = "Toyota";
final car2 = "Toyota";
print(car1 == car2); // Result: true

And if we want to compare two numbers, the code is:

  final phone1 = 52123456;
final phone2 = 52123456;
print(phone1 == phone2); // Result: true

Flutter Tip: Multiplicar en vez de dividir

· 2 min read
Yayo Arellano
Software Engineer
Youtube video player

Youtube video player

Hay veces que queremos calcular el ancho o la altura de un widget y tomamos como referencia el espacio de pantalla disponible. Por ejemplo en el siguiente fragmento de código, la altura de cada Container es la mitad del tamaño de la pantalla o MediaQuery.of(context).size.height / 2.

Column(
children: [
Container(
color: Colors.blue,
height: MediaQuery.of(context).size.height / 2,
),
Container(
color: Colors.green,
height: MediaQuery.of(context).size.height / 2,
)
],
)

Como podemos ver cada container ocupa la mitad de la pantalla: