Created
February 4, 2022 22:21
-
-
Save rurickdev/9660a9a1d76fb5f1209aa18ff54d41b3 to your computer and use it in GitHub Desktop.
This file contains 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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Column( | |
children: const [ | |
MyWidget.red(), | |
MyWidget.blue(), | |
MyWidget.green(), | |
MyWidget( | |
color: Colors.pink, | |
), | |
] | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
// main constructor | |
const MyWidget({required this.color}); | |
final Color color; | |
// Contructores nombrados que asignan | |
// la propiedad con un valor por defecto | |
const MyWidget.red(): color = Colors.red; | |
const MyWidget.green(): color = Colors.green; | |
const MyWidget.blue(): color = Colors.blue; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 100.0, | |
height: 100.0, | |
color: color, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment