Last active
October 9, 2022 05:49
-
-
Save Wachu985/fd314b0a563167ea46acc976ace8d869 to your computer and use it in GitHub Desktop.
Snippets para Dart y Flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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" | |
// } | |
"Rectángulo Widget": { | |
"prefix": "rectangulo", | |
"body": [ | |
"class Rectangulo extends StatelessWidget {", | |
" const Rectangulo({Key? key}) : super(key: key);", | |
" @override", | |
" Widget build(BuildContext context) {", | |
" return Container(", | |
" width: 70,", | |
" height: 70,", | |
" decoration: const BoxDecoration(", | |
" color: Colors.blue", | |
" ),", | |
" );", | |
" }", | |
"}", | |
], | |
"description": "Log output to console" | |
}, | |
"Flutter Page": { | |
"prefix": "fl-page", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"", | |
"class ${TM_FILENAME_BASE/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g} extends StatelessWidget {", | |
" static const String routeName = '${1:}';", | |
" const ${TM_FILENAME_BASE/((^[a-z])|_([a-z]))/${2:/upcase}${3:/upcase}/g}({Key? key}) : super(key: key);", | |
" @override", | |
" Widget build(BuildContext context) {", | |
" return const Scaffold(", | |
" body: Center(", | |
" child: ${2:Text('Hello World')},", | |
" ),", | |
" );", | |
" }", | |
"}", | |
], | |
"description": "Crea una página de flutter fácilmente" | |
}, | |
"Get Routes": { | |
"prefix": "get-routes", | |
"body": [ | |
"import 'package:flutter/material.dart';", | |
"", | |
"Map<String, Widget Function(BuildContext)> getRoutes() {", | |
" return {", | |
" ${1:page_name}.routeName: (context) => const ${1:page_name}(),", | |
" };", | |
"}", | |
], | |
"description": "Crea el Metodo de las Rutas" | |
}, | |
"Prefs Users": { | |
"prefix": "prefs-user", | |
"body": [ | |
"import 'package:shared_preferences/shared_preferences.dart';", | |
"", | |
"", | |
"class PreferenciasUsuario {", | |
" //==========Patron Singlenton=============", | |
" static final PreferenciasUsuario _instancia = PreferenciasUsuario._internal();", | |
" ", | |
" factory PreferenciasUsuario() {", | |
" return _instancia;", | |
" }", | |
"", | |
" PreferenciasUsuario._internal();", | |
" //==========Patron Singlenton=============", | |
"", | |
" SharedPreferences? _prefs;", | |
"", | |
" initPrefs() async {", | |
" _prefs = await SharedPreferences.getInstance();", | |
" }", | |
"", | |
" //GET y SET", | |
" get ${1:name} {", | |
" return _prefs!.getString('${1:name}') ?? 1;", | |
" }", | |
"", | |
" set ${1:name}(value) {", | |
" _prefs!.setString('${1:name}', value);", | |
" }", | |
"}", | |
], | |
"description": "Crea la Clase de Preferencias de Usuario" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment