Created with <3 with dartpad.dev.
Created
October 31, 2023 01:29
-
-
Save leonus96/71d50657e4e44f111ba88e80694ee6ba to your computer and use it in GitHub Desktop.
Null-safety
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// NULL Safety | |
/// Característica de Dart que ayuda a | |
/// prevenir error de valor nullo. | |
class Persona { | |
String nombre; | |
String? apodo; | |
Persona({required this.nombre, this.apodo}); | |
} | |
void main() { | |
final List<Persona> personas = [ | |
Persona( | |
nombre: 'Edinson Flores', | |
apodo: 'Orejas', | |
), | |
Persona(nombre: 'Miguel Trauco') | |
]; | |
for(Persona persona in personas) { | |
print('Nombre: ${persona.nombre}'); | |
if(persona.apodo != null) { | |
print('Apodo: ${persona.apodo}'); | |
} | |
print(''); | |
} | |
} | |
/*void conNullSafety() { | |
int? edad; | |
edad = 16; | |
edad = null; | |
print(edad); | |
}*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment