Dart
cotrVarStringMulti
Dart Create Multiline String Variable
String ${1:myString} = '''${2:Your string here}''';
cotrVarInt
Dart Create Integer Variable
int ${1:myInt} = ${2:0};
cotrVarDouble
Dart Create Double Variable
double ${1:myDouble} = ${2:0.0};
cotrComment
Dart Comment
// ${1:Your comment here}
cotrEqual
Dart Equal To
==
cotrTypes
Dart Types
$BLOCK_COMMENT_STARTDart is a statically typed language.
Types in Dart include:- num: A number type that can be either an int or a double- int: Integer- BigInt: Arbitrary-precision integer- double: Double-precision floating-point number- String: A sequence of characters- bool: Boolean- List: A list of elements- Map: A collection of key-value pairs- Set: A collection of unique elements- Runes: For expressing Unicode characters in a String- Symbol: An opaque, dynamic representation of a string in Dart
Read more here: https://dart.dev/language/built-in-types$BLOCK_COMMENT_END
cotrTypesInt
Dart Integer Type
int
cotrVar
Dart Create Variable
var ${1:myVar} = $2;
cotrTryCatch
Dart Try Catch
try { ${1:// Your code here}} catch (${2:exception}) { ${3:// Your code here}}
cotrIf
Dart If Statement
if (${1:condition}) { ${2:// Your code here}}
cotrEnum
Dart Enum
enum ${1:MyEnum} { ${2:value1}, ${3:value2}, // Add more values here}
cotrInfo
Dart Info
Typing: Statically typedParadigm: Multi-paradigm: object-oriented, functional, imperative, reflectiveCompilation: Compiled to native code or transpiled to JavaScriptConcurrency: Supports isolates for concurrent execution
cotrTypesDate
Dart Date Type
DateTime
cotrVarNullable
Dart Create Nullable Variable
${1:Type}? ${2:myVar} = $3;
cotrVarString
Dart Create String Variable
String ${1:myString} = ${2:'Your string here'};
cotrTypesNum
Dart Double Type
double
cotrForInLoop
Dart For…In Loop
for (var item in ${1:iterable}) { ${2:// Your code here}}
cotrThrow
Dart Throw Exception
throw ${1:Exception('Your message here')};
cotrTypesString
Dart String Type
String
cotrTypesNumAlt
Dart Float Type
float
cotrVarBool
Dart Create Boolean Variable
bool ${1:myBool} = ${2:true};
cotrGenMap
Dart Generate Map
var ${1:myMap} = Map.fromIterable(List.generate(${2:length}, (index) => index), key: (item) => 'key' + item.toString(), value: (item) => 'value' + item.toString(),);
cotrTypesMap
Dart Map Type
Map<${1:keyType}, ${2:valueType}>
cotrPrint
Dart Print
print(${1:'Your message here'});
cotrFuncSyntax
Dart Function Syntax
// Dart Function Syntax// Basic function: returnType functionName(parameters) { ... }// Function with arguments: returnType functionName(arg1Type arg1, arg2Type arg2, ...) { ... }// Function with named arguments: returnType functionName({arg1Type arg1, arg2Type arg2, ...}) { ... }
cotrInterpolate
Dart Interpolate String
'Your string here \${${1:variable}}'
cotrSwitch
Dart Switch Statement
switch (${1:variable}) { case ${2:value1}: ${3:// Your code here} break; case ${4:value2}: ${5:// Your code here} break; default: ${6:// Your code here}}
cotrStructure
Dart Project Structure (High-Level)
// Recommended High-Level Dart Project Structure:
// - lib/// - Contains the main Dart source files for the project.// - Organize by feature or functionality, for example:// - models/// - views/// - controllers/// - services/
// - web/ or bin/// - For web projects, `web/` contains HTML, CSS, and client-side Dart.// - For command-line or server-side projects, `bin/` contains the main entry point scripts.
// - test/// - Contains test files for the project, mirroring the structure of `lib/`.
// - pubspec.yaml// - The project's package and dependency management file.
// - build/// - Contains the output of the Dart build system.
// - doc/ or docs/// - Documentation for the project.
// Note:// - Adjust the structure as needed based on the specific project type and requirements.// - Use `web/` for web projects and `bin/` for server-side or command-line projects.
cotrOperators
Dart Mathematical Operators
// Dart Mathematical Operators// Addition: +// Subtraction: -// Multiplication: *// Exponentiation: **// Division: /// Modulus: %// Increment: ++// Decrement: --// Assignment: =// Addition assignment: +=// Subtraction assignment: -=// Multiplication assignment: *=// Division assignment: /=// Modulus assignment: %=
cotrTypeCheck
Dart Type Check
${1:variable}.runtimeType
cotrNow
Dart Date Now
DateTime.now()
cotrEntry
Dart Entry Point
// Dart Entry Point// To run this program, use: `dart run filename.dart`
void main() { // Your code here}
cotrFuncArgs
Dart Function Args
// In Dart, functions can have optional named or positional parameters with default values.${1:void} ${2:myFunction}(${3:Type} ${4:arg1}, [${5:Type} ${6:arg2} = ${7:defaultValue}]) { ${8:// Your code here}}
cotrClass
Dart Class
class ${1:MyClass} { ${2:// Your code here}}
cotrLambda
Dart Lambda Function
(${1:parameters}) => ${2:expression}
cotrForLoop
Dart For Loop
for (int ${1:i} = 0; $1 < ${2:10}; $1++) { // Your code here}
cotrFuncAnon
Dart Function Anonymous
(${1:parameters}) { ${2:// Your code here}}
cotrTypesBoolTrue
Dart Boolean True
true
cotrTypesBoolFalse
Dart Boolean False
false
cotrTypesList
Dart List Type
List<${1:type}>
cotrConst
Dart Create Constant
const ${1:myConst} = $2;
cotrTypesBool
Dart Boolean Type
bool
cotrVarMap
Dart Create Map Variable
Map<${1:KeyType}, ${2:ValueType}> ${3:myMap} = { ${4:key1}: ${5:value1}, ${6:key2}: ${7:value2}};
cotrWhileLoop
Dart While Loop
while (${1:condition}) { ${2:// Your code here}}
cotrNull
Dart Null Type
null
cotrVarStatic
Dart Static Variable
static ${2:var} ${3:myStaticVar} = ${4:value};
// Access the static variable// MyClass.${3:myStaticVar}
cotrTypeCompare
Dart Type Comparison
// Check if two variables have the same type:if (${1:variable1}.runtimeType == ${2:variable2}.runtimeType) { // Your code here}
cotrFuncArrow
Dart Function Arrow
${1:Type} ${2:myFunction}(${3:parameters}) => ${4:expression};
cotrVarList
Dart Create List Variable
List<${1:Type}> ${2:myList} = [${3:items}];
cotrVarDate
Dart Create Date Variable
DateTime ${1:myDate} = DateTime(${2:year}, ${3:month}, ${4:day});
cotrIfElse
Dart If Else Statement
if (${1:condition}) { ${2:// Your code here}} else if (${3:condition}) { ${4:// Your code here}} else { ${5:// Your code here}}
cotrTypesChar
Dart Character Type
char
cotrTypesDynamic
Dart Dynamic Type
dynamic
cotrVarSyntax
Variable Declaration Syntax
// Dart Variable Declaration Syntax:
// - var: (Scope: Block)// - Type is automatically inferred by the compiler.// - Preferred for most variable declarations.
// - type: (Scope: Block)// - Explicitly specify the variable's type.// - Use when var deduction is not desired or not possible.
// - const: (Scope: Block)// - Cannot be reassigned or redeclared.// - Use for values that should remain constant.
// - final: (Scope: Block)// - Cannot be reassigned, but can be declared without initialization.// - Use for variables that will be assigned a value later but should not change after that.
// Note:// - Use 'var' for most variable declarations.// - Use 'const' for values that are known at compile time.// - Use 'final' for variables that will be assigned later but should not change.
cotrNotEqual
Dart Not Equal To
!=
cotrTernary
Dart Ternary Operator
${1:condition} ? ${2:trueValue} : ${3:falseValue}
cotrOperatorsBool
Dart Boolean Operators
// Dart Boolean Operators// Logical AND: &&// Logical OR: ||// Logical NOT: !// Equality: ==// Inequality: !=// Greater than: >// Less than: <// Greater than or equal to: >=// Less than or equal to: <=
cotrTypeConvert
Dart Type Conversion
// Dart Type Conversion:
// Implicit conversions (compiler performs automatically):// - int to double (if no precision loss).
// Explicit conversions (using casts):// - variable as Type // Safe cast (returns null if conversion fails)// - Type.castFrom(variable) // Conversion methods
// Note:// - Be cautious with explicit conversions, as they can lead to data loss or errors if the conversion is not valid.
cotrVarTyped
Dart Create Typed Variable
${1:Type} ${2:myVar} = $3;
cotrConcat
Dart Concatenate Strings
'Your string here ' + ${1:variable}
cotrCommentMulti
Dart Multi-Line Comment
/* * ${1:Your comment here} */
cotrGenList
Dart Generate List
var ${1:myList} = List.generate(${2:length}, (index) => ${3:'item'} + index.toString());
cotrPrintMulti
Dart Print Multi
print('''${1:Line 1}${2:Line 2}${3:Line 3}''');
cotrFunc
Dart Function
${1:void} ${2:myFunction}(${3:parameters}) { ${4:// Your code here}}
cotrFuncArgsNamed
Dart Function Named Args
${1:void} ${2:myFunction}({${3:arg1}, ${4:arg2}}) { ${5:// Your code here}}