Skip to content

Instantly share code, notes, and snippets.

View xsahil03x's full-sized avatar
🤹‍♂️
Working on something awesome

Sahil Kumar xsahil03x

🤹‍♂️
Working on something awesome
View GitHub Profile
@xsahil03x
xsahil03x / main.dart
Created August 31, 2023 08:47
GoRouter black screen issue.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() => runApp(const MyApp());
/// The route configuration.
final GoRouter _router = GoRouter(
routes: <RouteBase>[
GoRoute(
@xsahil03x
xsahil03x / main.dart
Last active May 19, 2023 09:30
Aspect Ratio Expands
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. 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';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@xsahil03x
xsahil03x / select_value_notifier.dart
Created December 15, 2021 12:21
SelectValueNotifier
class _SelectValueNotifier<R, T> extends ValueNotifier<R> {
_SelectValueNotifier(this.source, this.selector)
: super(selector(source.value)) {
source.addListener(_sourceListener);
}
final ValueNotifier<T> source;
final R Function(T value) selector;
void _sourceListener() => value = selector(source.value);
@xsahil03x
xsahil03x / stream_message_text_field.dart
Last active October 25, 2021 12:03
StreamMessageTextField
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:stream_chat/stream_chat.dart';
class MessageInputController extends ValueNotifier<Message> {
/// Creates a controller for an editable text field.
///
/// This constructor treats a null [message] argument as if it were the empty
@xsahil03x
xsahil03x / counter_button.dart
Created August 30, 2021 19:23
Simple counter button
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rxdart/rxdart.dart';
typedef CounterEdit = Future<bool> Function(int);
/// Returns true if the [valueBeforeZero] is handled by user.
typedef OnValueZero = Future<bool> Function(int valueBeforeZero);
abstract class EventSyncHelper {
void startSession();
Future<void> sendEvent(Event event);
Future<VoidResult> syncRemainingEvents();
void endSession();
}
class Streamable<T> extends Subject<T> implements ValueStream<T> {
Streamable(this._subject) : super(_subject, _subject);
final BehaviorSubject<T> _subject;
@override
Subject<R> createForwardingSubject<R>({
void Function()? onListen,
void Function()? onCancel,
bool sync = false,
@xsahil03x
xsahil03x / event_emitter.dart
Last active March 15, 2021 12:14
Dart Event Emitter
import 'dart:async';
import 'dart:collection';
import 'package:meta/meta.dart';
/// A listener that can be added to a [EventEmitter] using
/// [EventEmitter.on] or [EventEmitter.addListener].
///
/// This callback gets invoked once we call [EventEmitter.emit].
typedef Listener<T> = void Function(T data);
@xsahil03x
xsahil03x / rate_limit.dart
Created March 5, 2021 18:24
RxDart based implementation of rate limit
import 'dart:async';
import 'package:rxdart/rxdart.dart';
class StreamDebounce {
final Function func;
final Duration interval;
final subject = PublishSubject<List<dynamic>>();
StreamSubscription subscriber;
@xsahil03x
xsahil03x / rate_limit.dart
Created March 5, 2021 16:20
Rate Limit similar to `stream_transformer`
import 'dart:async';
/// Signature for for the static method [Function.apply].
typedef ApplicableFunction = void Function(
List<dynamic> positionalArguments, {
Map<Symbol, dynamic> namedArguments,
});
/// Useful rate limiter extensions for [Function] class.
extension RateLimit on Function {