/* --------------------------------------------- 100 -------------------------------------------- */ import 'dart:io'; // void main() { // print("please enter your age"); // String? _age = stdin.readLineSync(); // int age = int.parse(_age!); // int turn100 = 100 - age; // print("your age is $turn100"); // if (age%2 > 0) { // print("your age is odd"); // } // else if (age%2 == 0) { // print("your age is even"); // } // } abstract class Component { final String id; final double x; final double y; final String themeColor; final bool isVisible; // The base constructor sets the foundation Component({ required this.id, required this.x, required this.y, this.themeColor = 'blue', // Default value this.isVisible = true, // Default value }); void render(); } class Button extends Component { final String label; final double width; final double height; Button({ // --- Unique to Button --- required this.label, required this.width, required this.height, // --- Passed to Component via super. --- required super.id, required super.x, required super.y, super.themeColor, // Doesn't require coz if user not define it defaults to parent's 'blue'. But if user provide value, use super to assign provided value to parent class variable. super.isVisible, // Doesn't require coz if user not define, it defaults to parent's 'true' // "assert" is a "sanity check" that runs before the class is even fully created. It ensures you can't accidentally create an invisible button with a width of -50. If the condition fails, the program crashes (in debug mode) with your custom error message. }) : assert(width > 0 && height > 0, 'Dimensions must be positive'); @override void render() { print('Rendering Button "$label" at ($x, $y) with color $themeColor'); } } void main() { final loginBtn = Button( label: 'Login', width: 200, height: 50, id: 'btn_001', x: 100, y: 500, themeColor: 'green', // Overriding the default ); loginBtn.render(); } // ------------------------------------------------------------------