Skip to content

Instantly share code, notes, and snippets.

@vishna
vishna / carousel.dart
Created July 21, 2020 17:41 — forked from slightfoot/carousel.dart
Scrolling Carousel with centered variable width items and snapping - By Simon Lightfoot - 20/07/2020
// MIT License
//
// Copyright (c) 2019 Lukasz Wisniewski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@vishna
vishna / suspend_var.kt
Last active January 23, 2022 15:49
Suspened Variable in Kotlin - works kinda lateinit but if your variable is late, it will make you wait rather than crash
class SuspendedVariable<T>(var scope: CoroutineScope? = GlobalScope) {
private var actor = scope?.actor<Op<T>> {
var value : T? = null
val deferrals = mutableListOf<CompletableDeferred<T>>()
try {
for (message in channel) {
when (message) {
is Op.Set -> {
@vishna
vishna / syntax_highlighter.dart
Last active March 1, 2021 11:47 — forked from X-Wei/syntax_highlighter.dart
syntax-highlighter for flutter_markdown (adopted from flutter_gallery) + nullsafety + range error fix
// Copyright 2016 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 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart' show SyntaxHighlighter;
import 'package:string_scanner/string_scanner.dart';
class SyntaxHighlighterStyle {
SyntaxHighlighterStyle(
@vishna
vishna / debounce-broadcast.kt
Created November 5, 2017 19:38
Debounce input from an EditText and relay to a TextView with a timeout.
package me.vishna.kdebounce
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.UI
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.media.AudioManager;
import android.media.MediaFormat;
import android.media.MediaPlayer;
import android.net.Uri;
@vishna
vishna / navigator_observer_delegate.dart
Created February 4, 2020 13:31
navigator_observer_delegate.dart
// utility class so that you don't have to extend from [NavigatorObserver] but rather
/// pass the function you want
class NavigatorObserverDelegate extends NavigatorObserver {
NavigatorObserverDelegate(
{this.onDidPush,
this.onDidPop,
this.onDidRemove,
this.onDidReplace,
this.onDidStartUserGesture,
this.onDidStopUserGesture});
@vishna
vishna / widget_tester_rich_edit.dart
Created February 3, 2020 14:31
WidgetTester RichEdit Extension - find a piece of text, e.g. tap a link in the text
/// found nothing better than this
/// https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/hyperlink_test.dart#L47
/// sooo...
extension WidgetTesterRichEditExtension on WidgetTester {
Iterable<InlineSpan> findTextSpans(
Finder richTextFinder, bool Function(InlineSpan) predicate) {
final richText = widget<RichText>(richTextFinder);
expect(richText.text, isInstanceOf<TextSpan>());
final TextSpan innerText = richText.text;
return innerText.children.where(predicate);
import io.flutter.embedding.android.FlutterActivity // there are two FlutterActivities :|
import io.flutter.plugins.GeneratedPluginRegistrant // this is not seen by IntelliJ by works ¯\_(ツ)_/¯
typealias FlutterCallback = (methodCall: MethodCall, result: MethodChannel.Result) -> Unit
class FlutterPathActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
infix fun String.handles(callHandler: FlutterCallback) {
MethodChannel(flutterEngine.dartExecutor, this).setMethodCallHandler(callHandler)
}
#!/bin/sh
# Makes the bash script to print out every command before it is executed except echo
trap '[[ $BASH_COMMAND != echo* ]] && echo $BASH_COMMAND' DEBUG
echo "Executing steps to repro issue #37852"
echo "https://github.com/flutter/flutter/issues/37852"
echo "MAKE SURE YOU'RE ON MASTER CHANNEL!"
echo "MAKE SURE YOU HAVE iOS SIMULATOR RUNNING"