Skip to content

Instantly share code, notes, and snippets.

View rafaelqueiroz88's full-sized avatar
🔷
Darting

Rafael Queiroz de Castro rafaelqueiroz88

🔷
Darting
View GitHub Profile
@rafaelqueiroz88
rafaelqueiroz88 / base_service.dart
Created February 19, 2025 14:15
Generic Request
import 'dart:convert';
import 'package:http/http.dart' as http;
abstract class BaseService {
static const String baseUrl = 'http://some-supercool-api-address:s0m3-p0rt';
final String endpoint;
late final Map<String, dynamic> response;
BaseService({required this.endpoint});
@rafaelqueiroz88
rafaelqueiroz88 / sized_box_minus_app_bar.dart
Last active February 17, 2025 13:50
SizedBox height - app bar - status bar
SizedBox(
height: MediaQuery.of(context).size.height -
kToolbarHeight - // Default AppBar size
MediaQuery.of(context).padding.top, // Default status bar size
child: Text(''),
);
@rafaelqueiroz88
rafaelqueiroz88 / workflow.yml
Created June 10, 2024 11:53
Ruby on Rails + Github Actions
name: "Ruby on Rails trigger Github Actions"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
@rafaelqueiroz88
rafaelqueiroz88 / get_random_element.dart
Created January 24, 2024 17:14
Get some element at random from array
bool getRandomElement(List<bool> list) => list[Random().nextInt(list.length)];
import 'package:flutter_week_view/flutter_week_view.dart';
DateTime now = DateTime.now();
DateTime date = DateTime(now.year, now.month, now.day);
DayView dayView() {
return DayView(
date: now,
events: [
FlutterWeekViewEvent(
@rafaelqueiroz88
rafaelqueiroz88 / find_week_start_or_end.dart
Created October 25, 2023 13:02
Find first and last DateTime of a week
void main() {
// Find first date and last date of CURRENT WEEK
DateTime today = DateTime.now();
print(findFirstDateOfTheWeek(today));
print(findLastDateOfTheWeek(today));
// Find first date and last date of any provided date
DateTime date = DateTime.parse('2023-09-01');
print(findFirstDateOfTheWeek(date));
print(findLastDateOfTheWeek(date));
@rafaelqueiroz88
rafaelqueiroz88 / password.dart
Created October 8, 2023 14:21
Encrypting locally password before request
import 'dart:convert';
// package needed: https://pub.dev/packages/crypto
import 'package:crypto/crypto.dart';
void main() {
var passwordBytes = utf8.encode("s0me-super-cool-p@$$WorD-here");
var passwordEncrypt = sha256.convert(passwordBytes);
@rafaelqueiroz88
rafaelqueiroz88 / password_check.dart
Created October 4, 2023 00:29
Dart Regular Expression (Refex)
/**
* It forces strong passwords
* @require String password
* @return bool
*
* return true if password has:
* 1 capitalized character
* 1 special character
* 1 number
*/
@rafaelqueiroz88
rafaelqueiroz88 / test.dart
Created September 20, 2023 19:06
Flutter test internet connection
void testConnection() async {
try {
final connection = await InternetAddress.lookup('www.google.com');
if (connection.isNotEmpty && connection.first.rawAddress.isNotEmpty) {
hasConnection = true;
}
} on SocketException catch (_) {
hasConnection = false;
}
}
@rafaelqueiroz88
rafaelqueiroz88 / drawer.dart
Created August 21, 2023 15:26
Flutter Drawer Example
import 'package:flutter/material.dart';
class AppDrawer extends StatelessWidget {
const AppDrawer({super.key});
@override
Widget build(BuildContext context) {
return Drawer(
backgroundColor: Colors.white,
child: Column(