Skip to content

Instantly share code, notes, and snippets.

View felipecarvalho's full-sized avatar
🎯
Focusing

Felipe Carvalho felipecarvalho

🎯
Focusing
  • São Paulo, Brazil
View GitHub Profile
@felipecarvalho
felipecarvalho / inject.dart
Last active May 21, 2024 19:07
Inject JS on webview_flutter
void _injectJS(controller) {
controller.runJavaScript('''
function dispatchButtonEvent(element, func) {
const button = document.querySelector(element);
button.addEventListener("click", function() {
setTimeout(func, "$_delayTime");
});
}
function changeValue(itemId, itemValue) {
@felipecarvalho
felipecarvalho / git-clean-history
Last active July 15, 2021 15:10
Clean commit history
git init
git add .
git commit -m 'Initial commit'
git branch -M main
git remote add origin [repo_address]
git push --mirror --force
@felipecarvalho
felipecarvalho / color.dart
Created July 7, 2020 20:56
Custom color swatch for MaterialColor on Flutter
MaterialColor createMaterialColor(Color color) {
List strengths = <double>[.05];
Map swatch = <int, Color>{};
final int r = color.red, g = color.green, b = color.blue;
for (int i = 1; i < 10; i++) {
strengths.add(0.1 * i);
}
strengths.forEach((strength) {
final double ds = 0.5 - strength;
@felipecarvalho
felipecarvalho / main.dart
Created March 15, 2019 21:21
Using FOR structure with ASYNC and FUTURE to create a timer with response in Dart language
// Created by Felipe Carvalho [http://github.com/felipecarvalho]
// You can play with this code on DartPad [https://dartpad.dartlang.org/2ca102102a010ff0b6162d896cadaee3]
void main() async {
int start = 10;
int timeout = 1;
print("The clock's alarm is running...");
for (int i = start; i >= timeout; i--) {
@felipecarvalho
felipecarvalho / main.dart
Last active March 14, 2019 21:40
Filtering values from a object in Dart language
// Created by Felipe Carvalho [http://github.com/felipecarvalho]
// You can play with this code on DartPad [https://dartpad.dartlang.org/32780de6b46a387d621344f05ed54c63]
List<Map<String, dynamic>> _fruits = [
{"id": 0, "name": "Orange"},
{"id": 1, "name": "Mango"},
{"id": 2, "name": "Apple"},
];
void main() {
@felipecarvalho
felipecarvalho / main.dart
Last active March 11, 2019 00:21
Snippet to check brazilian license plate from vehicles in Dart language
// Created by Felipe Carvalho [http://github.com/felipecarvalho]
// You can play with this code on DartPad [https://dartpad.dartlang.org/1d41821144a1645428ff4a3000d5d74a]
void main() {
String _regOldPlate = r"^[a-zA-Z]{3}[-][0-9]{4}$";
String _regNewPlate = r"^[a-zA-Z]{3}[0-9]{1}[a-zA-Z]{1}[0-9]{2}$";
RegExp _currentPlate;
void checkNewPlate(bool _value, String _plate) {
_currentPlate = RegExp(_value ? _regNewPlate : _regOldPlate, caseSensitive: false, multiLine: false);
@felipecarvalho
felipecarvalho / codes.json
Last active February 26, 2023 17:09
JSON list with country and phone codes in portuguese [PT-BR]
[
{
"dialCode": "93",
"code": "AFG",
"label": "Afeganistão"
},
{
"dialCode": "355",
"code": "ALB",
"label": "Albânia"
@felipecarvalho
felipecarvalho / fix-node-link.md
Last active November 7, 2018 05:54
Instructions to fix "env: node: no such file or directory" error if you've installed Node via NVM through Homebrew on macOS