Skip to content

Instantly share code, notes, and snippets.

@shinayser
shinayser / isolate_compute.dart
Created July 29, 2019 22:00
Easy access to Isolate's computing function.
// 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 =
@shinayser
shinayser / servers_test.dart
Last active July 29, 2019 22:08
Just playing with Dart's server capabilities
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();
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?",
#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 June 21, 2020 12:50 — forked from ajmaln/downloadFile.dart
Download file with progress in Dart/Flutter using 'http' package
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",
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;
@shinayser
shinayser / split_load.dart
Created August 19, 2020 19:03
This transformer splits the source stream data between all the listeners
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();
///
@shinayser
shinayser / get_flutter_dir.dart
Created April 13, 2021 22:25
Get flutter dir on PATH
import 'package:path/path.dart' as path;
String getFlutterBinFolderPath() {
final pathString = Platform.environment['PATH'];
if (pathString == null) {
throw 'Flutter bin folder not located on PATH';
}
final flutterPath = pathString.split(';').firstWhere(
class LateralNavigationPageRoute<T> extends MaterialPageRoute<T> {
LateralNavigationPageRoute({
required WidgetBuilder builder,
RouteSettings? settings,
}) : super(builder: builder, settings: settings);
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) =>
SlideTransition(
@shinayser
shinayser / email_regex
Created June 29, 2021 13:28
Email regex RFC 5322
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])