Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "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 Database Helper" : {
- "prefix": "sqfliteDatabaseHelper",
- "body": [
- "import 'package:sqflite/sqflite.dart';",
- "import 'dart:async';",
- "import 'dart:io';",
- "import 'package:path_provider/path_provider.dart';",
- "",
- "class DatabaseHelper {",
- "",
- "\tstatic DatabaseHelper _databaseHelper;",
- "\tstatic Database _database;",
- "",
- "\tDatabaseHelper._createInstance();",
- "",
- "\tfactory DatabaseHelper(){",
- "",
- "\t\tif(_databaseHelper == null){",
- "\t\t\t_databaseHelper = DatabaseHelper._createInstance();",
- "\t\t}",
- "",
- "\t\treturn _databaseHelper;",
- "\t}",
- "",
- "\tFuture<Database> get database async{",
- "",
- "\t\tif(_database == null){",
- "\t\t\t_database = await initializeDatabase();",
- "\t\t}",
- "",
- "\t\treturn _database;",
- "\t}",
- "",
- "\tFuture<Database> initializeDatabase() async{",
- "\t\tDirectory directory = await getApplicationDocumentsDirectory();",
- "\t\tString path = directory.path + \"${1:database_name}\";",
- "",
- "\t\tvar mDatabase = await openDatabase(path, version: 1, onCreate: _createDb);",
- "\t\treturn mDatabase;",
- "\t}",
- "",
- "\tvoid _createDb(Database db, int newVersion) async {",
- "\t\tawait db.execute(\"${2:query for create table}\");",
- "\t}",
- "}",
- ]
- },
- "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