Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@danielgomezrico
danielgomezrico / await.dart
Last active Mar 18, 2022
List.await • dart: example to see the order of the returned results
View await.dart
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 Feb 14, 2022
UseCase / Interactor - naming convention to use with use cases
View call_example.dart
class UpdateUserInteractor {
Future<void> call(String name) async {
print("done $name");
return;
}
}
void main() async {
final updateUser = UpdateUserInteractor();
await updateUser('Dan');
View result_monad_2
///
/// The Result Monad
///
abstract class Result<T> {
bool isSuccess() {
return this is Success;
}
Success<T> asSuccess() {
return this as Success<T>;
@danielgomezrico
danielgomezrico / result_monad_1.dart
Last active Feb 9, 2022
Result Monad as example
View result_monad_1.dart
///
/// The Result Monad
///
abstract class Result<T> {
bool isSuccess() {
return this is Success;
}
Success<T> asSuccess() {
@danielgomezrico
danielgomezrico / Dangerfile.rb
Created Jan 8, 2022
DangerFile - Danger System - script to check conventional commits titles and size of the PR
View Dangerfile.rb
# https://www.regextester.com/109925
CONVENTIONS_URL = "your link"
def validate_title_format
def valid_title_format?(title)
conventional_commit_regex = /^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?: .*$/
result = title =~ conventional_commit_regex
result != nil
end
View markdown-details-collapsible.md

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets
@danielgomezrico
danielgomezrico / update_list.dart
Created Mar 5, 2021
Example showing how to update a list
View update_list.dart
class Person {
Person(this.name);
final String name;
String toString() => name;
}
void main() {
final items = [Person("juan"), Person("pedro"), Person("coso")];
@danielgomezrico
danielgomezrico / yield.dart
Created Feb 5, 2021
Dart - simple yield and yield* example
View yield.dart
Stream<String> otherNumbers() {
return Stream.fromIterable(["2", "3"]);
}
Stream<String> allNumbers() async* {
yield "1";
yield* otherNumbers();
}
@danielgomezrico
danielgomezrico / check-format.sh
Created Dec 27, 2020
Flutter - Check code format and fail if does not work, useful for CI flows
View check-format.sh
#!/usr/bin/env bash
#
# Runs dartfmt from dart_style to check if all of the source files are well formatted
# Requires you to have dartfmt already in your path with 'pub global activate dart_style'
#
echo "-> Running 'flutter format' to check project dart style 🤓"
RESULT=$(flutter format -n lib/main.dart lib/src/ test/)
@danielgomezrico
danielgomezrico / provider_generic_extensions.dart
Last active Nov 28, 2020
Dart/Flutter - Extensions to emit ChangeNotifier changes as a Stream, very useful for unit testing
View provider_generic_extensions.dart
/// Function to get the changed value everytime
typedef GetChangeFunction<T> = T Function();
extension AsStream<T> on ChangeNotifier {
Stream<T> statusAsStream(GetChangeFunction<T> getChange) {
final controller = StreamController<T>();
// Redirect status changes into the Stream