Flutter Dart Cheat Sheet for TypeScript Developers
February 8, 2024
Welcome to "Flutter Dart Cheat Sheet for TypeScript Developers". This article is meant to be a quick reference guide for software developers already familiar with TypeScript who are looking to expand their expertise into Flutter app development using Dart.
Variables and Constants
// TypeScript
var myVar: string = "hello world";
let myLet: string = "hello world";
const myConst:string = "hello world";
// Dart
var myVar = "hello world"; // Inferred type
const String myConst = "hello world"; // Compile-time constant
final String myFinal = "hello world"; // Set the value at run-time once
late String myLateVar; // Set the value laterasync/await
// TypeScript
async myFunction (myArg: string): Promise<void> {
// await something
}
// Dart
Future<void> myFunction (String myArg) async {
// await something
}Console.log / Print
// TypeScript
console.log("hello world");
// Dart
print("hello world");String interpolation
// TypeScript
const welcomeText = `Hello ${firstName}`;
// Dart
final welcomeText = 'Hello $firstName';setTimeout
// TypeScript
const myTimeout = setTimeout(() => {
// do something
}, 1000);
clearTimeout(myTimeout);
// Dart
import 'dart:async';
...
final myTimeout = Timer(Duration(seconds: 1), () {
// do something
});
myTimeout.cancel();setInterval
// TypeScript
const myInterval = setInterval(() => {
// do something
}, 1000);
clearInterval(myInterval);
// Dart
import 'dart:async';
...
final myInterval = Timer.periodic(Duration(seconds: 1), (timer) {
// do something
});
myInterval.cancel();About StratusCube
StratusCube makes software for everyday use along with software engineering articles. If you enjoined this article, please take a moment to browse our apps or check out more articles .
