Skip to content

Instantly share code, notes, and snippets.

@rurickdev
Created February 4, 2022 22:21
Show Gist options
  • Save rurickdev/9660a9a1d76fb5f1209aa18ff54d41b3 to your computer and use it in GitHub Desktop.
Save rurickdev/9660a9a1d76fb5f1209aa18ff54d41b3 to your computer and use it in GitHub Desktop.
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