This commit is contained in:
2026-03-27 18:13:39 +07:00
parent 476e414630
commit 88c8bc7d7a
2 changed files with 85 additions and 0 deletions

0
dart_ex_1/etc.md Normal file
View File

85
dart_ex_1/main.dart Normal file
View File

@@ -0,0 +1,85 @@
/* --------------------------------------------- 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();
}
// ------------------------------------------------------------------