Counter with Event Callbacks - Dart Typing CST Test
Loading…
Counter with Event Callbacks — Dart Code
Uses callback functions to handle increment, decrement, and reset events.
void main() {
int count = 0;
void onUpdate(int value) => print('Counter: $value');
void increment(void Function(int) callback) {
count++;
callback(count);
}
void decrement(void Function(int) callback) {
count--;
callback(count);
}
void reset(void Function(int) callback) {
count = 0;
callback(count);
}
increment(onUpdate);
increment(onUpdate);
decrement(onUpdate);
reset(onUpdate);
}Dart Language Guide
Dart is a modern, object-oriented programming language developed by Google, optimized for building web, server, and mobile applications, particularly for Flutter. It emphasizes performance, strong typing, and productive development.
Primary Use Cases
- ▸Mobile app development with Flutter
- ▸Web applications and progressive web apps (PWAs)
- ▸Server-side applications with Dart VM
- ▸Command-line tools and scripts
- ▸Cross-platform desktop applications
Notable Features
- ▸Strongly typed with sound null safety
- ▸Ahead-of-time (AOT) and just-in-time (JIT) compilation
- ▸Hot reload for fast development cycles
- ▸Rich standard library and asynchronous support
- ▸Interoperability with JavaScript for web development
Origin & Creator
Created in 2011 by Google, designed by Lars Bak and Kasper Lund.
Industrial Note
Dart is specialized for cross-platform development, especially for Flutter, enabling single codebases for mobile, web, and desktop applications.