diff --git a/snippets/dart/array-manipulation/even-filter.md b/snippets/dart/array-manipulation/even-filter.md new file mode 100644 index 00000000..02c7909f --- /dev/null +++ b/snippets/dart/array-manipulation/even-filter.md @@ -0,0 +1,12 @@ +--- +title: Filter a List +description: Filters a list to include only even numbers. +author: Vrindtime +tags: dart,collections,list,utility +--- + +```dart +final numbers = [1, 2, 3, 4, 5, 6]; +final evens = numbers.where((n) => n.isEven).toList(); +print(evens); // Prints [2, 4, 6] +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/find-index.md b/snippets/dart/array-manipulation/find-index.md new file mode 100644 index 00000000..b0c39392 --- /dev/null +++ b/snippets/dart/array-manipulation/find-index.md @@ -0,0 +1,12 @@ +--- +title: Find Index of an Element +description: Finds and prints the index of a specific element in an array. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [10, 20, 30, 40, 50]; +final index = numbers.indexOf(30); +print(index); // Prints 2 +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/max-value.md b/snippets/dart/array-manipulation/max-value.md new file mode 100644 index 00000000..67d8be0e --- /dev/null +++ b/snippets/dart/array-manipulation/max-value.md @@ -0,0 +1,12 @@ +--- +title: Find Maximum in an Array +description: Finds and prints the maximum value in an array. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [3, 7, 2, 9, 4]; +final maxNumber = numbers.reduce((a, b) => a > b ? a : b); +print(maxNumber); // Prints 9 +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/remove-duplicate.md b/snippets/dart/array-manipulation/remove-duplicate.md new file mode 100644 index 00000000..9ed81c6b --- /dev/null +++ b/snippets/dart/array-manipulation/remove-duplicate.md @@ -0,0 +1,12 @@ +--- +title: Remove Duplicates from an Array +description: Removes duplicate elements from an array and prints the result. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [1, 2, 2, 3, 4, 4, 5]; +final uniqueNumbers = numbers.toSet().toList(); +print(uniqueNumbers); // Prints [1, 2, 3, 4, 5] +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/remove-element.md b/snippets/dart/array-manipulation/remove-element.md new file mode 100644 index 00000000..e8f2d56a --- /dev/null +++ b/snippets/dart/array-manipulation/remove-element.md @@ -0,0 +1,12 @@ +--- +title: Remove Specific Element from an Array +description: Removes a specific element from an array and prints the result. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [1, 2, 3, 4, 5]; +numbers.remove(3); +print(numbers); // Prints [1, 2, 4, 5] +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/reverse-array.md b/snippets/dart/array-manipulation/reverse-array.md new file mode 100644 index 00000000..0e3fdf61 --- /dev/null +++ b/snippets/dart/array-manipulation/reverse-array.md @@ -0,0 +1,12 @@ +--- +title: Reverse an Array +description: Reverses an array and prints the result. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [1, 2, 3, 4, 5]; +final reversed = numbers.reversed.toList(); +print(reversed); // Prints [5, 4, 3, 2, 1] +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/shuffle-array.md b/snippets/dart/array-manipulation/shuffle-array.md new file mode 100644 index 00000000..6468b9ba --- /dev/null +++ b/snippets/dart/array-manipulation/shuffle-array.md @@ -0,0 +1,12 @@ +--- +title: Shuffle an Array +description: Randomly shuffles the elements of an array and prints the result. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [1, 2, 3, 4, 5]; +numbers.shuffle(Random()); +print(numbers); // Prints the array in random order +``` \ No newline at end of file diff --git a/snippets/dart/array-manipulation/sort-array.md b/snippets/dart/array-manipulation/sort-array.md new file mode 100644 index 00000000..92b5dc0b --- /dev/null +++ b/snippets/dart/array-manipulation/sort-array.md @@ -0,0 +1,12 @@ +--- +title: Sort an Array +description: Sorts an array in ascending order and prints it. +author: Vrindtime +tags: dart,array-manipulation,utility +--- + +```dart +final numbers = [5, 1, 8, 3, 2]; +numbers.sort(); +print(numbers); // Prints [1, 2, 3, 5, 8] +``` \ No newline at end of file diff --git a/snippets/dart/basics/hello-world.md b/snippets/dart/basics/hello-world.md new file mode 100644 index 00000000..8f7ffd26 --- /dev/null +++ b/snippets/dart/basics/hello-world.md @@ -0,0 +1,10 @@ +--- +title: Hello, World! +description: Prints Hello, World! to the terminal. +author: Vrindtime +tags: dart,printing,hello-world,utility +--- + +```dart +print("Hello, World!"); // Prints Hello, World! to the console +``` \ No newline at end of file diff --git a/snippets/dart/date-and-time/add-duration.md b/snippets/dart/date-and-time/add-duration.md new file mode 100644 index 00000000..ceba878c --- /dev/null +++ b/snippets/dart/date-and-time/add-duration.md @@ -0,0 +1,12 @@ +--- +title: Add Duration to DateTime +description: Adds a specified duration to a DateTime object and prints the result. +author: Vrindtime +tags: dart,date-time,utility +--- + +```dart +final now = DateTime.now(); +final future = now.add(Duration(days: 7,hours: 10,minutes: 5,seconds: 2,microseconds: 100,milliseconds: 50)); +print(future); // Prints the date and time 7 days, 10 hours, 5 minutes, 2 seconds, 100 microseconds and 50 miliseconds from now +``` \ No newline at end of file diff --git a/snippets/dart/date-and-time/format-date.md b/snippets/dart/date-and-time/format-date.md new file mode 100644 index 00000000..32f75d38 --- /dev/null +++ b/snippets/dart/date-and-time/format-date.md @@ -0,0 +1,12 @@ +--- +title: Format DateTime +description: Formats a DateTime object into a human-readable string. +author: Vrindtime +tags: dart,date-time,utility +--- + +```dart +final now = DateTime.now(); +final formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now); +print(formattedDate); // Prints the formatted date, e.g., "2025-01-01 – 14:35" +``` \ No newline at end of file diff --git a/snippets/dart/date-and-time/get-date-time.md b/snippets/dart/date-and-time/get-date-time.md new file mode 100644 index 00000000..f39d3b16 --- /dev/null +++ b/snippets/dart/date-and-time/get-date-time.md @@ -0,0 +1,11 @@ +--- +title: Get Current Date and Time +description: Retrieves and prints the current date and time. +author: Vrindtime +tags: dart,date-time,utility +--- + +```dart +final now = DateTime.now(); +print(now); // Prints the current date and time +``` \ No newline at end of file diff --git a/snippets/dart/date-and-time/string-to-date.md b/snippets/dart/date-and-time/string-to-date.md new file mode 100644 index 00000000..cb7a7593 --- /dev/null +++ b/snippets/dart/date-and-time/string-to-date.md @@ -0,0 +1,12 @@ +--- +title: Parse Date from String +description: Parses a date string into a DateTime object and prints it. +author: Vrindtime +tags: dart,date-time,utility +--- + +```dart +final dateString = "2025-01-01 15:30:00"; +final parsedDate = DateTime.parse(dateString); +print(parsedDate); // Prints "2025-01-01 15:30:00.000" +``` \ No newline at end of file diff --git a/snippets/dart/date-and-time/time-difference.md b/snippets/dart/date-and-time/time-difference.md new file mode 100644 index 00000000..4ce18730 --- /dev/null +++ b/snippets/dart/date-and-time/time-difference.md @@ -0,0 +1,14 @@ +--- +title: Calculate Time Difference +description: Calculates the difference between two DateTime objects in days, hours, and minutes. +author: Vrindtime +tags: dart,date-time,utility +--- + +```dart +final start = DateTime(2025, 1, 1, 12, 0); +final end = DateTime(2025, 1, 2, 14, 30); +final difference = end.difference(start); +print('Days: ${difference.inDays}, Hours: ${difference.inHours}, Minutes: ${difference.inMinutes}'); +// Prints "Days: 1, Hours: 26, Minutes: 1590" +``` diff --git a/snippets/dart/file-manipulation/append-to-file.md b/snippets/dart/file-manipulation/append-to-file.md new file mode 100644 index 00000000..f256f3f8 --- /dev/null +++ b/snippets/dart/file-manipulation/append-to-file.md @@ -0,0 +1,12 @@ +--- +title: Append to a File +description: Appends text to an existing file and prints a confirmation. +author: Vrindtime +tags: dart,file-manipulation,io,utility +--- + +```dart +final file = File('example.txt'); +await file.writeAsString('Appended text.', mode: FileMode.append); //remember to use aync modifier in the function +print('Text appended successfully.'); +``` \ No newline at end of file diff --git a/snippets/dart/file-manipulation/delete-file.md b/snippets/dart/file-manipulation/delete-file.md new file mode 100644 index 00000000..961efa1a --- /dev/null +++ b/snippets/dart/file-manipulation/delete-file.md @@ -0,0 +1,16 @@ +--- +title: Delete a File +description: Deletes a specified file and prints a confirmation. +author: Vrindtime +tags: dart,file-manipulation,io,utility +--- + +```dart +final file = File('example.txt'); +if (await file.exists()) { + await file.delete(); //remember to use aync modifier in the function + print('File deleted successfully.'); +} else { + print('File does not exist.'); +} +``` \ No newline at end of file diff --git a/snippets/dart/file-manipulation/list-files-directory.md b/snippets/dart/file-manipulation/list-files-directory.md new file mode 100644 index 00000000..fe9e7112 --- /dev/null +++ b/snippets/dart/file-manipulation/list-files-directory.md @@ -0,0 +1,14 @@ +--- +title: List Files in a Directory +description: Lists all files in a directory and prints their names. +author: Vrindtime +tags: dart,file-manipulation,io,utility +--- + +```dart +final directory = Directory.current; +final files = directory.listSync(); +for (var file in files) { + print(file.path); // Prints the paths of all files and directories +} +``` \ No newline at end of file diff --git a/snippets/dart/file-manipulation/read-file.md b/snippets/dart/file-manipulation/read-file.md new file mode 100644 index 00000000..3e3d3f03 --- /dev/null +++ b/snippets/dart/file-manipulation/read-file.md @@ -0,0 +1,12 @@ +--- +title: Read a File +description: Reads the content of a file and prints it to the console. +author: Vrindtime +tags: dart,file-manipulation,io,utility +--- + +```dart +final file = File('example.txt'); +final content = await file.readAsString(); +print(content); // Prints the content of the file +``` \ No newline at end of file diff --git a/snippets/dart/file-manipulation/write-file.md b/snippets/dart/file-manipulation/write-file.md new file mode 100644 index 00000000..6af3366c --- /dev/null +++ b/snippets/dart/file-manipulation/write-file.md @@ -0,0 +1,12 @@ +--- +title: Write to a File +description: Writes text to a file and prints a confirmation. +author: Vrindtime +tags: dart,file-manipulation,io,utility +--- + +```dart +final file = File('example.txt'); +await file.writeAsString('Hello, Dart!'); //remember to use aync modifier in the function +print('File written successfully.'); +``` \ No newline at end of file diff --git a/snippets/dart/icon.svg b/snippets/dart/icon.svg new file mode 100644 index 00000000..ae53e4f0 --- /dev/null +++ b/snippets/dart/icon.svg @@ -0,0 +1,11 @@ + +Dart Logo Square + + + + + + + + + diff --git a/snippets/dart/string-manipulation/contain-string.md b/snippets/dart/string-manipulation/contain-string.md new file mode 100644 index 00000000..e95f60ed --- /dev/null +++ b/snippets/dart/string-manipulation/contain-string.md @@ -0,0 +1,12 @@ +--- +title: Check if String Contains Substring +description: Checks if a string contains a specific substring and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'Learning Dart is fun!'; +final contains = input.contains('Dart'); +print(contains); // Prints true +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/convert-to-uppercase.md b/snippets/dart/string-manipulation/convert-to-uppercase.md new file mode 100644 index 00000000..eb31de22 --- /dev/null +++ b/snippets/dart/string-manipulation/convert-to-uppercase.md @@ -0,0 +1,12 @@ +--- +title: Convert to Uppercase +description: Converts a string to uppercase and prints it. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final original = "hello, world!"; +final uppercased = original.toUpperCase(); +print(uppercased); // Prints "HELLO, WORLD!" +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/count-character.md b/snippets/dart/string-manipulation/count-character.md new file mode 100644 index 00000000..623509f9 --- /dev/null +++ b/snippets/dart/string-manipulation/count-character.md @@ -0,0 +1,12 @@ +--- +title: Count Characters in a String +description: Counts the number of characters in a string and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'Dart'; +final length = input.length; +print(length); // Prints 4 +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/extract-substring.md b/snippets/dart/string-manipulation/extract-substring.md new file mode 100644 index 00000000..79746c2d --- /dev/null +++ b/snippets/dart/string-manipulation/extract-substring.md @@ -0,0 +1,12 @@ +--- +title: Extract Substring +description: Extracts a portion of a string and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'Hello, Dart!'; +final substring = input.substring(7, 11); +print(substring); // Prints 'Dart' +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/isString-palindrome.md b/snippets/dart/string-manipulation/isString-palindrome.md new file mode 100644 index 00000000..c5b1db49 --- /dev/null +++ b/snippets/dart/string-manipulation/isString-palindrome.md @@ -0,0 +1,12 @@ +--- +title: Check if a String is a Palindrome +description: Checks if a string is a palindrome and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'madam'; +final isPalindrome = input == input.split('').reversed.join(''); +print(isPalindrome); // Prints true +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/replace-substring.md b/snippets/dart/string-manipulation/replace-substring.md new file mode 100644 index 00000000..f064c36f --- /dev/null +++ b/snippets/dart/string-manipulation/replace-substring.md @@ -0,0 +1,12 @@ +--- +title: Replace Substring +description: Replaces all occurrences of a substring with another substring and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'Dart is great!'; +final replaced = input.replaceAll('great', 'awesome'); +print(replaced); // Prints 'Dart is awesome!' +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/reverse-string.md b/snippets/dart/string-manipulation/reverse-string.md new file mode 100644 index 00000000..432b5110 --- /dev/null +++ b/snippets/dart/string-manipulation/reverse-string.md @@ -0,0 +1,12 @@ +--- +title: Reverse a String +description: Reverses a string and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'Dart'; +final reversed = input.split('').reversed.join(''); +print(reversed); // Prints 'traD' +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/split-string.md b/snippets/dart/string-manipulation/split-string.md new file mode 100644 index 00000000..855a4cf7 --- /dev/null +++ b/snippets/dart/string-manipulation/split-string.md @@ -0,0 +1,12 @@ +--- +title: Split String by Delimiter +description: Splits a string into a list of substrings using a delimiter and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = 'apple,banana,cherry'; +final fruits = input.split(','); +print(fruits); // Prints [apple, banana, cherry] +``` \ No newline at end of file diff --git a/snippets/dart/string-manipulation/trim-whitespace.md b/snippets/dart/string-manipulation/trim-whitespace.md new file mode 100644 index 00000000..1d221702 --- /dev/null +++ b/snippets/dart/string-manipulation/trim-whitespace.md @@ -0,0 +1,12 @@ +--- +title: Trim Whitespace +description: Removes leading and trailing whitespace from a string and prints the result. +author: Vrindtime +tags: dart,string-manipulation,utility +--- + +```dart +final input = ' Dart is fun! '; +final trimmed = input.trim(); +print(trimmed); // Prints 'Dart is fun!' +``` \ No newline at end of file