Skip to content

Instantly share code, notes, and snippets.

View MacDeveloper1's full-sized avatar

MacDeveloper1

  • Heteren, Netherlands
View GitHub Profile
/// Provides a functionality for capture the widget as image.
class WidgetToImage {
WidgetToImage._();
/// Captures the widget.
///
/// The [pixelRatio] describes the scale between the logical pixels and the
/// size of the output image. It is independent of the
/// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0
/// (the default) will give you a 1:1 mapping between logical pixels and the
@MacDeveloper1
MacDeveloper1 / debounced_scroll_controller.dart
Created September 6, 2023 11:04
DebouncedScrollController
class DebouncedScrollController extends ScrollController {
DebouncedScrollController({
super.initialScrollOffset,
super.keepScrollOffset,
super.debugLabel,
super.onAttach,
super.onDetach,
this.debounceTime = const Duration(milliseconds: 150),
}) {
_streamSubscription = _streamController.stream
@MacDeveloper1
MacDeveloper1 / web_hydrated_storage.dart
Created September 6, 2023 09:28
WebHydratedStorage
/// {@template web_hydrated_storage}
/// Implementation of [Storage] which uses session storage of web browser
/// to persist and retrieve state changes.
/// {@endtemplate}
class WebHydratedStorage implements Storage {
const WebHydratedStorage()
: assert(kIsWeb, 'WebHydratedStorage is only available on web platform');
/// Returns instance of [WebStorage].
@MacDeveloper1
MacDeveloper1 / base_hydrated_bloc.dart
Created September 6, 2023 09:27
BaseHydratedBloc
/// Base hydrated [Bloc] which saves its state apart for authenticated user.
abstract class BaseHydratedBloc<TEvent, TState>
extends HydratedBloc<TEvent, TState> with StreamSubscriptionMixin<TState> {
/// Abstract constructor. This constructor provides an initial [state] and
/// optional [id] (usually user identifier) which is used to change a
/// [storagePrefix].
BaseHydratedBloc(super.state, {int? id}) {
authenticatedUserId ??= id;
}
@MacDeveloper1
MacDeveloper1 / scrollable_debounce.dart
Created September 6, 2023 09:24
ScrollableDebouce
class ScrollableDebounce extends StatefulWidget {
const ScrollableDebounce({
Key? key,
required this.controller,
required this.onScroll,
this.debounceTime = const Duration(milliseconds: 200),
required this.child,
}) : super(key: key);
/// An object that can be used to control the position to which this scroll