Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adding the dart language #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CreeperFarm wants to merge 2 commits into quicksnip-dev:main from CreeperFarm:main
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/consolidated/_index.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"lang": "CSS",
"icon": "/icons/css.svg"
},
{
"lang": "DART",
"icon": "/icons/dart.svg"
},
{
"lang": "HASKELL",
"icon": "/icons/haskell.svg"
Expand Down
60 changes: 60 additions & 0 deletions public/consolidated/dart.json
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{
"categoryName": "Basic",
"snippets": [
{
"title": "Hello, World!",
"description": "Prints Hello, World! to the terminal.",
"author": "CreeperFarm",
"tags": [
"printing",
"hello-world"
],
"contributors": [],
"code": "print(\"Hello, World!\"); // Prints Hello, World! to the console\n"
}
]
},
{
"categoryName": "Flutter",
"snippets": [
{
"title": "Button ElevatedButton",
"description": "Display a button with a border and elevation set automatically",
"author": "CreeperFarm",
"tags": [
"button",
"flutter",
"widget"
],
"contributors": [],
"code": "ElevatedButton(\n onPressed: () {\n // Do something when the button is pressed\n },\n child: Text('Click me!'),// Display the text Click me!\n) \n\n// If you want a button with an icon\nElevatedButton.icon(\n onPressed: () {\n // Do something when the button is pressed\n },\n icon: Icon(Icons.add), // Show the add icon\n label: Text('Add'), // Display the text Add\n)\n"
},
{
"title": "Button InkWell",
"description": "Display a button who is clickable in his whole area where his child is displayed",
"author": "CreeperFarm",
"tags": [
"button",
"flutter",
"widget"
],
"contributors": [],
"code": "InkWell(\n onTap: () {\n // Do something when the button is pressed\n },\n child: Container( // Create a container to hold any widget\n padding: EdgeInsets.all(12.0),\n child: Text('Click me!'), // Display the text Click me!\n ),\n)\n"
},
{
"title": "Custom Icon",
"description": "Display a custom icon from an .svg file, with the file inside the assets folder. The following code must be added to a components folder then icons folder inside the lib folder. This code should be inside a file called custom_icon.dart . You must have the package flutter_svg in your pubspec.yaml file.",
"author": "CreeperFarm",
"tags": [
"flutter",
"widget",
"icon",
"svg"
],
"contributors": [],
"code": "import 'package:flutter/material.dart';\nimport 'package:flutter_svg/flutter_svg.dart';\n\nclass CustomIcon extends StatelessWidget {\n Color iconColor;\n final String iconName;\n final double? height;\n\n CustomIcon({required this.iconColor, required this.iconName, this.height, super.key});\n\n @override\n Widget build(BuildContext context) {\n return SvgPicture.asset(\n 'assets/icons/$iconName.svg', // The path to the .svg file\n colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn), // Change the icon's color\n height: height?.toDouble(), // If the height is null, it will be be set as the svg's default height\n );\n }\n}\n"
}
]
}
]
18 changes: 6 additions & 12 deletions public/consolidated/javascript.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@
"description": "Converts RGB color values to hexadecimal color code.",
"author": "jjcantu",
"tags": [
"javascript",
"color",
"conversion",
"utility"
"conversion"
],
"contributors": [],
"code": "function rgbToHex(r, g, b) {\n const toHex = (n) => {\n const hex = n.toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n \n return '#' + toHex(r) + toHex(g) + toHex(b);\n}\n\n// Usage:\nconsole.log(rgbToHex(255, 128, 0)); // Output: \"#ff8000\"\nconsole.log(rgbToHex(0, 255, 0)); // Output: \"#00ff00\"\n"
Expand Down Expand Up @@ -407,10 +405,8 @@
"description": "Converts bytes into human-readable file size format.",
"author": "jjcantu",
"tags": [
"javascript",
"format",
"size",
"utility"
"size"
],
"contributors": [],
"code": "function formatFileSize(bytes) {\n if (bytes === 0) return '0 Bytes';\n \n const k = 1024;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n \n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];\n}\n\n// Usage:\nconsole.log(formatFileSize(1234)); // Output: \"1.21 KB\"\nconsole.log(formatFileSize(1234567)); // Output: \"1.18 MB\"\n"
Expand Down Expand Up @@ -506,13 +502,11 @@
"description": "Creates a deep copy of an object or array without reference.",
"author": "jjcantu",
"tags": [
"javascript",
"object",
"clone",
"utility"
"clone"
],
"contributors": [],
"code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: { a: 1, b: { c: 2 }, d: [1, 2, 3] }\n"
"code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: 'original' but cloned\n"
},
{
"title": "Filter Object",
Expand Down Expand Up @@ -758,9 +752,9 @@
"description": "Generates a UUID (v4) string.",
"author": "jjcantu",
"tags": [
"javascript",
"uuid",
"utility"
"generate",
"string"
],
"contributors": [],
"code": "function generateUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n const r = Math.random() * 16 | 0;\n const v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}\n\n// Usage:\nconsole.log(generateUUID()); // Output: \"a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5\"\n"
Expand Down
1 change: 1 addition & 0 deletions public/icons/dart.svg
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
10 changes: 10 additions & 0 deletions snippets/dart/basic/hello-world.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Hello, World!
description: Prints Hello, World! to the terminal.
author: CreeperFarm
tags: printing,hello-world
---

```dart
print("Hello, World!"); // Prints Hello, World! to the console
```
24 changes: 24 additions & 0 deletions snippets/dart/flutter/button-elevatedbutton.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Button ElevatedButton
description: Display a button with a border and elevation set automatically.
author: CreeperFarm
tags: button,widget
---

```dart
ElevatedButton(
onPressed: () {
// Do something when the button is pressed
},
child: Text('Click me!'),// Display the text Click me!
)

// If you want a button with an icon
ElevatedButton.icon(
onPressed: () {
// Do something when the button is pressed
},
icon: Icon(Icons.add), // Show the add icon
label: Text('Add'), // Display the text Add
)
```
18 changes: 18 additions & 0 deletions snippets/dart/flutter/button-inkwell.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Button InkWell
description: Display a button who is clickable in his whole area where his child is displayed
author: CreeperFarm
tags: button,widget
---

```dart
InkWell(
onTap: () {
// Do something when the button is pressed
},
child: Container( // Create a container to hold any widget
padding: EdgeInsets.all(12.0),
child: Text('Click me!'), // Display the text Click me!
),
)
```
35 changes: 35 additions & 0 deletions snippets/dart/flutter/custom-icon.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Custom Icon
description: Display a custom icon from an .svg file, with the file inside the assets folder. The following code must be added to a components folder then icons folder inside the lib folder. This code should be inside a file called custom_icon.dart . You must have the package flutter_svg in your pubspec.yaml file.
author: CreeperFarm
tags: widget,icon,svg
---

```dart
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class CustomIcon extends StatelessWidget {
Color iconColor;
final String iconName;
final double? height;

CustomIcon({required this.iconColor, required this.iconName, this.height, super.key});

@override
Widget build(BuildContext context) {
return SvgPicture.asset(
'assets/icons/$iconName.svg', // The path to the .svg file
colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn), // Change the icon's color
height: height?.toDouble(), // If the height is null, it will be be set as the svg's default height
);
}
}

// Usage:
CustomIcon(
iconColor: Colors.red, // Set the icon's color
iconName: 'icon_name', // Set the icon's name
height: 24, // Set the icon's height
)
```
67 changes: 67 additions & 0 deletions snippets/dart/icon.svg
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /