Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gomez danielgomezrico

View GitHub Profile
@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
@danielgomezrico
danielgomezrico / example.dart
Last active Aug 15, 2020
Flutter - Android - extensions to mock more easy on testing with mockito
View example.dart
// The abstractions
abstract class Result<T> {
}
class Success<T> extends Result<T> {
final T body;
Success(this.body);
}
@danielgomezrico
danielgomezrico / generics_failure.dart
Created Aug 15, 2020
Generics failure example with dart
View generics_failure.dart
abstract class Result<T> { }
class Success<T> extends Result<T> {
final T body;
Success(this.body);
}
class Failure<T> extends Result<T> {
@danielgomezrico
danielgomezrico / jacoco.gradle
Last active Jun 18, 2020
Jacoco setup to merge coverage for android when you run unit tests + integration tests and get a mixed result
View jacoco.gradle
// Merge of
// https://github.com/mgouline/android-samples/blob/master/jacoco/app/build.gradle
// and https://github.com/pushtorefresh/storio/blob/master/gradle/jacoco-android.gradle
// Requires Jacoco plugin in build classpath.
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.3"
}
@danielgomezrico
danielgomezrico / gist:cbd98365a840a93c4e6a04e25b2b1671
Last active Oct 9, 2019
Android - How to transform from List<T> to Observable<PageList<T>> for androidx paging library
View gist:cbd98365a840a93c4e6a04e25b2b1671
package com.lahaus.utils.extensions
import androidx.paging.DataSource
import androidx.paging.PagedList
import androidx.paging.PositionalDataSource
import androidx.paging.RxPagedListBuilder
import io.reactivex.Observable
fun <T> List<T>.toObservablePagedList(): Observable<PagedList<T>> {
val defaultConfig = PagedList.Config.Builder()
@danielgomezrico
danielgomezrico / jacoco.gradle
Created May 16, 2019
Android / Gradle - Jacoco gradle setup to join instrumentation and unit test coverage
View jacoco.gradle
// Merge of
// https://github.com/mgouline/android-samples/blob/master/jacoco/app/build.gradle
// and https://github.com/pushtorefresh/storio/blob/master/gradle/jacoco-android.gradle
// Requires Jacoco plugin in build classpath.
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.3"
}
@danielgomezrico
danielgomezrico / add-spaces.sh
Created May 3, 2019
Add empty space recursively on each file for current folder
View add-spaces.sh
for f in $(find . -name '*.kt')
do
echo "" >> "$f"
done