Skip to content

Instantly share code, notes, and snippets.

@fvisticot
fvisticot / blurhash.js
Created April 22, 2020 08:22
BlurHash test
const blurhash = require('blurhash');
const { createCanvas, loadImage, Image } = require('canvas')
const getImageData = (image) => {
const canvas = createCanvas(image.width, image.height)
const context = canvas.getContext('2d')
context.drawImage(image, 0, 0)
return context.getImageData(0, 0, image.width, image.height)
}
@fvisticot
fvisticot / sliding_sheet_webview
Created April 13, 2020 13:41
Sliding Sheet WebView
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:sliding_sheet/sliding_sheet.dart';
import 'package:webview_flutter/webview_flutter.dart';
class SlidingSheetWebView extends StatefulWidget {
@override
_SlidingSheetWebViewState createState() => _SlidingSheetWebViewState();
}
@fvisticot
fvisticot / main.dart
Created December 24, 2019 22:43
Stream yield async
import 'dart:async';
void main() async {
Future<int> computeCost(int val) async {
await Future.delayed(Duration(seconds: 1));
return val * 2;
}
Stream<int> generateValues1() {
return Stream.periodic(Duration(seconds: 1), (val) {
@fvisticot
fvisticot / main.dart
Last active December 24, 2019 17:38
Completer
import 'dart:async';
void main() async{
Future<int>testTimer(int i) {
final completer=Completer<int>();
Timer(Duration(seconds: 5), () {
print("coucou from :$i");
if (i != 3)
completer.complete(i);
@fvisticot
fvisticot / main.dart
Last active October 4, 2019 09:18
Exemple
void main() {
print("Hello world");
}
@fvisticot
fvisticot / main.dart
Last active October 3, 2019 22:38
Divers...
void main() {
var book1 = Book("Titre", null);
var book2 = null;
print("${book1.description}");
print("${book2?.description}");
var test = book1.description ?? "default";
print(test);
@fvisticot
fvisticot / main.dart
Last active October 3, 2019 22:31
Singleton
void main() {
print(new Singleton() == new Singleton());
}
class Singleton {
static final Singleton _instance = Singleton._internal();
Singleton._internal();
factory Singleton() => _instance;
@fvisticot
fvisticot / main.dart
Last active October 3, 2019 22:27
lambda
void main() {
const books = [
const Book('book1', "book1 desc"),
const Book('book2', "book2 desc")
];
print("Books: $books");
books.forEach((book) => print("${book.title}"));
@fvisticot
fvisticot / main.dart
Last active October 3, 2019 22:20
Exceptions
void main() {
int res = ComputeService().add(2, 4);
print("Res: $res");
try {
int res = ComputeService().add(null, 4);
print("Res: $res");
} on ComputeServiceException catch (e){
print("Error: ${e.cause}");
}
@fvisticot
fvisticot / main.dart
Created October 3, 2019 21:59
Abstract class
void main() {
Car car1 = Car("Car1");
car1.go();
car1.sayHello();
}
abstract class Vehicule {
final String name;
Vehicule(this.name);