Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- // Place your snippets for dart here. Each snippet is defined under a snippet name and has a prefix, body and
- // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
- // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
- // same ids are connected.
- // Example:
- // "Print to console": {
- // "prefix": "log",
- // "body": [
- // "console.log('$1');",
- // "$2"
- // ],
- // "description": "Log output to console"
- // }
- "Create Stateful Widget" : {
- "prefix": "statefulWidget",
- "body": [
- "class ${1:className}Page extends StatefulWidget{",
- "\t@override",
- "\t_${1:className}PageState createState() => _${1:className}PageState();",
- "}",
- "\n",
- "class _${1:className}PageState extends State<${1:className}Page>{",
- "\t@override",
- "\tWidget build(BuildContext context){",
- "\t\treturn Scaffold(",
- "\t\t\tappBar: AppBar(",
- "\t\t\t\ttitle: Text('${1:className}')",
- "\t\t\t),",
- "\t\t\tbody: Center(",
- "\t\t\t\tchild: Text('${1:className}')",
- "\t\t\t)",
- "\t\t);",
- "\t}",
- "}",
- ],
- "description": "Class Statefull set"
- },
- "SQFLite Get Map List" : {
- "prefix": "sqfliteGetMapList",
- "body": [
- "// Fetch $1MapList",
- "Future<List<Map<String, dynamic>>> $1GetMapList(Map<String, dynamic> filters) async {",
- "\tDatabase db = await this.database;",
- "\tvar result = List<Map<String, dynamic>>();",
- "",
- "\tList whereStringList = List();",
- "\tif(filters.length > 0) { ",
- "\t\tfilters.forEach((k, v){",
- "\t\t\tif(v != null) {",
- "\t\t\t\tvar number = int.parse(v);",
- "\t\t\t\tif(number.isEven || number.isOdd) {",
- "\t\t\t\t\twhereStringList.add(\" \\$k = \\$v\");",
- "\t\t\t\t}else{",
- "\t\t\t\t\twhereStringList.add(\" \\$k = '\\$v'\");",
- "\t\t\t\t}",
- "\t\t\t}",
- "\t\t});",
- "",
- "\t\tString whereString = \"\";",
- "\t\tif (whereStringList.length > 0) {",
- "\t\t\twhereString = whereStringList.join(\" and \");",
- "\t\t}",
- "\n",
- "\t\tif(whereString.isNotEmpty) {",
- "\t\t\tresult = await db.query(\"$1\", where: whereString, orderBy: '$2 asc');",
- "\t\t}else{",
- "\t\t\tresult = await db.query(\"$1\", orderBy: '$2 asc');",
- "\t\t}",
- "",
- "\t}",
- "\treturn result;",
- "}",
- ]
- },
- "SQFLite Replace" : {
- "prefix": "sqfliteReplace",
- "body": [
- "// Replace Operation : Replace $1 Object to Database",
- "Future<int> $2Replace($1 $2) async {",
- "\tDatabase db = await this.database;",
- "",
- "\tvar result = 0;",
- "\tif($2.$3 != null && $2.$3 > 0){",
- "\t\tresult = await db.update(\"$2\", $2.toMap(), where: \"$3 = \\${$2.$3}\");",
- "\t}else{",
- "\t\tresult = await db.insert(\"$2\", $2.toMap());",
- "\t}",
- "\treturn result;",
- "}"
- ]
- },
- "SQFLite Update" : {
- "prefix": "sqfliteUpdate",
- "body": [
- "// Update operation : update $1 to database",
- "Future<int> $2Update($1 $2) async{",
- "\tDatabase db = await this.database;",
- "",
- "\tvar result = await db.update(\"$2\", $2.toMap(), where: '$3 = ?', whereArgs: [$2.$3]);",
- "\treturn result;",
- "}"
- ]
- },
- "SQFLite Delete" : {
- "prefix": "sqfliteDelete",
- "body": [
- "// Delete operation : delete $1 object from Database",
- "Future<int> $1Delete(int id) async {",
- "\tDatabase db = await this.database;",
- "",
- "\tvar result = await db.rawDelete('DELETE FROM $1 WHERE $2 = \\$$2}');",
- "\treturn result;",
- "}"
- ]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement