Advertisement
Guest User

Dart fo Flutter

a guest
Jan 23rd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.58 KB | None | 0 0
  1. {
  2.     // Place your snippets for dart here. Each snippet is defined under a snippet name and has a prefix, body and
  3.     // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  4.     // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
  5.     // same ids are connected.
  6.     // Example:
  7.     // "Print to console": {
  8.     //  "prefix": "log",
  9.     //  "body": [
  10.     //      "console.log('$1');",
  11.     //      "$2"
  12.     //  ],
  13.     //  "description": "Log output to console"
  14.     // }
  15.  
  16.     "Create Stateful Widget" : {
  17.         "prefix": "statefulWidget",
  18.         "body": [
  19.             "class ${1:className}Page extends StatefulWidget{",
  20.             "\t@override",
  21.             "\t_${1:className}PageState createState() => _${1:className}PageState();",
  22.             "}",
  23.             "\n",
  24.             "class _${1:className}PageState extends State<${1:className}Page>{",
  25.             "\t@override",
  26.             "\tWidget build(BuildContext context){",
  27.             "\t\treturn Scaffold(",
  28.             "\t\t\tappBar: AppBar(",
  29.             "\t\t\t\ttitle: Text('${1:className}')",
  30.             "\t\t\t),",
  31.             "\t\t\tbody: Center(",
  32.             "\t\t\t\tchild: Text('${1:className}')",
  33.             "\t\t\t)",
  34.             "\t\t);",
  35.             "\t}",
  36.             "}",
  37.         ],
  38.         "description": "Class Statefull set"
  39.     },
  40.  
  41.     "SQFLite Get Map List" : {
  42.         "prefix": "sqfliteGetMapList",
  43.         "body": [
  44.             "// Fetch $1MapList",
  45.             "Future<List<Map<String, dynamic>>> $1GetMapList(Map<String, dynamic> filters) async {",
  46.             "\tDatabase db = await this.database;",
  47.             "\tvar result = List<Map<String, dynamic>>();",
  48.             "",
  49.             "\tList whereStringList = List();",
  50.             "\tif(filters.length > 0) { ",
  51.             "\t\tfilters.forEach((k, v){",
  52.             "\t\t\tif(v != null) {",
  53.             "\t\t\t\tvar number = int.parse(v);",
  54.             "\t\t\t\tif(number.isEven || number.isOdd) {",
  55.             "\t\t\t\t\twhereStringList.add(\" \\$k = \\$v\");",
  56.             "\t\t\t\t}else{",
  57.             "\t\t\t\t\twhereStringList.add(\" \\$k = '\\$v'\");",
  58.             "\t\t\t\t}",
  59.             "\t\t\t}",
  60.             "\t\t});",
  61.             "",
  62.             "\t\tString whereString = \"\";",
  63.             "\t\tif (whereStringList.length > 0) {",
  64.             "\t\t\twhereString = whereStringList.join(\" and \");",
  65.             "\t\t}",
  66.             "\n",
  67.             "\t\tif(whereString.isNotEmpty) {",
  68.             "\t\t\tresult = await db.query(\"$1\", where: whereString, orderBy: '$2 asc');",
  69.             "\t\t}else{",
  70.             "\t\t\tresult = await db.query(\"$1\", orderBy: '$2 asc');",
  71.             "\t\t}",
  72.             "",
  73.             "\t}",
  74.             "\treturn result;",
  75.             "}",
  76.         ]
  77.     },
  78.  
  79.     "SQFLite Replace" : {
  80.         "prefix": "sqfliteReplace",
  81.         "body": [
  82.            
  83.             "// Replace Operation : Replace $1 Object to Database",
  84.             "Future<int> $2Replace($1 $2) async {",
  85.             "\tDatabase db = await this.database;",
  86.             "",
  87.             "\tvar result = 0;",
  88.             "\tif($2.$3 != null && $2.$3 > 0){",
  89.             "\t\tresult = await db.update(\"$2\", $2.toMap(), where: \"$3 = \\${$2.$3}\");",
  90.             "\t}else{",
  91.             "\t\tresult = await db.insert(\"$2\", $2.toMap());",
  92.             "\t}",
  93.             "\treturn result;",
  94.             "}"
  95.         ]  
  96.     },
  97.  
  98.     "SQFLite Update" : {
  99.         "prefix": "sqfliteUpdate",
  100.         "body": [
  101.             "// Update operation : update $1 to database",
  102.             "Future<int> $2Update($1 $2) async{",
  103.             "\tDatabase db = await this.database;",
  104.             "",
  105.             "\tvar result = await db.update(\"$2\", $2.toMap(), where: '$3 = ?', whereArgs: [$2.$3]);",
  106.             "\treturn result;",
  107.             "}"
  108.         ]      
  109.     },
  110.  
  111.     "SQFLite Delete" : {
  112.         "prefix": "sqfliteDelete",
  113.         "body": [
  114.            
  115.             "// Delete operation : delete $1 object from Database",
  116.             "Future<int> $1Delete(int id) async {",
  117.             "\tDatabase db = await this.database;",
  118.             "",
  119.             "\tvar result = await db.rawDelete('DELETE FROM $1 WHERE $2 = \\$$2}');",
  120.             "\treturn result;",
  121.             "}"
  122.         ]        
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement