Skip to content

Instantly share code, notes, and snippets.

@shinayser
shinayser / split_load.dart
Created Aug 19, 2020
This transformer splits the source stream data between all the listeners
View split_load.dart
import 'dart:async';
extension LoadSplitterTransformerExtension<T> on Stream<T> {
///Splits the data events between all the listeners.
///The error events are still being emitted to all of them.
///
/// ### Example
///
/// var splitted = Stream.fromIterable([1, 2, 3]).splitLoad();
///
View visibility_aware_state.dart
import 'package:flutter/material.dart';
/*This must be added to your MaterialApp`s navigatorObservers, like:
* navigatorObservers: [routeObserver]
*/
final routeObserver = RouteObserver<PageRoute>();
abstract class VisibilityAwareState<T extends StatefulWidget>
extends State<T> with WidgetsBindingObserver, RouteAware {
bool _isOnScreen = true;
View build-on-push.yaml
#This Github Action builds the Dart 'bin' folder on every push commited to GitHub
name: Build on push
on: [push]
jobs:
build:
runs-on: ${{ matrix.os }}
@shinayser
shinayser / download_file.dart
Last active Jun 21, 2020 — forked from ajmaln/downloadFile.dart
Download file with progress in Dart/Flutter using 'http' package
View download_file.dart
import 'dart:async';
import 'dart:io';
import 'package:http/http.dart' as http;
///Returns the file as a stream of bytes
Future<Stream<List<int>>> downloadAsStream(String url) async {
var result = await Client().send(
Request(
"get",
View desafio_peixe_babel.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
const kAmountOfSentences = 8;
const kSentences = [
"Já defendeu o TCC?",
"Quantos artigos esse ano?",
"E as namoradinhas?",
@shinayser
shinayser / value_listenable_stream.dart
Created Aug 9, 2019
A function that converts a ValueListenable to a Stream
View value_listenable_stream.dart
Stream<T> valueListenableToStreamAdapter<T>(ValueListenable<T> listenable) {
StreamController<T> controller;
void listener() {
controller.add(listenable.value);
}
void start() {
listenable.addListener(listener);
}
@shinayser
shinayser / servers_test.dart
Last active Jul 29, 2019
Just playing with Dart's server capabilities
View servers_test.dart
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
import 'package:http/http.dart' as http;
// ignore_for_file: unawaited_futures
void main([List<String> args]) {
// prefix0.main(["15900152"]);
_buildServers();
@shinayser
shinayser / isolate_compute.dart
Created Jul 29, 2019
Easy access to Isolate's computing function.
View isolate_compute.dart
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:developer';
import 'dart:isolate';
import 'package:meta/meta.dart';
const bool kReleaseMode =
You can’t perform that action at this time.