Skip to content

Instantly share code, notes, and snippets.

View danielgomezrico's full-sized avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / pubspec.yaml
Created May 2, 2024 21:20
Flutter - Built Value - Build Runner: script to update pubscpec with the files to autogenerate
targets:
$default:
builders:
built_value_generator:built_value:generate_for:
generate_for:
- HERE
@danielgomezrico
danielgomezrico / result.dart
Created March 20, 2024 19:59
Example - Study: check if typedef works for type checks
import 'dart:async';
typedef FutureResult<T> = Future<Result<T>>;
typedef FutureOrResult<T> = FutureOr<Result<T>>;
typedef ConcatResult<F, S> = ({F first, S second});
abstract class Result<T> {
const Result();
@danielgomezrico
danielgomezrico / readme.md
Created January 5, 2024 17:21
i18n performance test using i18n.Of, temporal variables and i18n.current

Results are:

With Current

  • direclty access to i18n(RunTime): 55185442.5 us.
  • indireclty access to i18n(RunTime): 55758307.0 us.
  • indireclty outside access to i18n(RunTime): 56177293.5 us.

With BuildContext

  • direclty access to i18n(RunTime): 92459941.0 us.
  • indireclty access to i18n(RunTime): 83667963.5 us.
@danielgomezrico
danielgomezrico / Manifest.xml
Created December 13, 2023 21:47
Flutter · Dart: web server to start a local webserver
<!-- Attribute to add on android -->
<app
....
android:usesCleartextTraffic="true">
...
</app>
@danielgomezrico
danielgomezrico / pre-commit.sh
Created January 20, 2023 16:32
Git - Hook - Pre Commit - Flutter: format files before they are commited
#!/bin/sh
#
# Autoformat all modified files before commit
#
function format_if_required {
FILES=$1
flutter format $FILES | grep -Ev '^(Unchanged)'
@danielgomezrico
danielgomezrico / pre-commit.sh
Created December 14, 2022 17:22
Git - hook - pre-commit: for flutter/dart format each modified file ultra fast before each commit
#!/bin/sh
#
# Autoformat all modified files before commit
#
function format_if_required {
FILES=$1
flutter format $FILES | grep -Ev '^(Unchanged)'
@danielgomezrico
danielgomezrico / build.dart
Last active August 24, 2022 20:22
Dart - how to create a url with query params with language features
// Use language features to build the url
String buildUrlWithQueryParams(String url, Map<String, dynamic> queryParams) {
final uri = Uri.parse(url);
final fullUri = uri.replace(
queryParameters: {
...uri.queryParameters,
...queryParams,
},
);
@danielgomezrico
danielgomezrico / comment_with_pr_number.yml
Created July 15, 2022 19:57
Github Action - Comment on PR using the PR number
name: PR Commenter
on:
pull_request:
types: [opened, reopened]
jobs:
comment:
runs-on: ubuntu-latest
steps:
@danielgomezrico
danielgomezrico / await.dart
Last active March 18, 2022 22:01
List.await • dart: example to see the order of the returned results
import 'dart:async';
Future main() async {
print('start');
final li = await Future.wait([fetch(4), fetch(6)]);
print('results: ${li[0]} ${li[1]}'); // results: 4 2
final li2 = await Future.wait([fetch(6), fetch(3)]);
print('results 2: ${li2[0]} ${li2[1]}'); // results: 6 3
@danielgomezrico
danielgomezrico / call_example.dart
Created February 14, 2022 18:05
UseCase / Interactor - naming convention to use with use cases
class UpdateUserInteractor {
Future<void> call(String name) async {
print("done $name");
return;
}
}
void main() async {
final updateUser = UpdateUserInteractor();
await updateUser('Dan');