Skip to content

Instantly share code, notes, and snippets.

import "package:flutter/material.dart";
abstract class Controller extends ChangeNotifier {
static T ofType<T extends Controller>(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<_ControllerModel<T>>()!
.controller;
}
static T? maybeOfType<T extends Controller>(BuildContext context) {
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:uri/uri.dart';
class PathRouteMatch {
PathRouteMatch(
{required this.parameters,
required this.route,
@jezell
jezell / main.dart
Created September 2, 2024 20:27
Context Menu Hell
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
void main() => runApp(const EditableTextToolbarBuilderExampleApp());
class EditableTextToolbarBuilderExampleApp extends StatefulWidget {
const EditableTextToolbarBuilderExampleApp({super.key});
@jezell
jezell / auto_overlay_portal.dart
Created September 4, 2024 02:13
Auto Overlay Portal
import "package:flutter/material.dart";
class AutoOverlayPortal extends StatefulWidget {
const AutoOverlayPortal(
{super.key, required this.overlayChildBuilder, this.child});
final Widget Function(BuildContext) overlayChildBuilder;
final Widget? child;
@override
@jezell
jezell / main.dart
Last active September 27, 2024 17:25
Flutter web compositor memory leak
// Copyright 2019 the Dart project 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 'dart:js_interop';
void main() => runApp(const MyApp());
@JS('window.flutterCanvasKit.HEAP8.byteLength')
import "package:flutter/material.dart";
class FutureRegistry {
final List<Future> _futures = [];
void register(Future f) {
_futures.add(f);
f.whenComplete(() {
_futures.remove(f);
});
@jezell
jezell / main.dart
Created October 24, 2024 01:38
3.27.1 compiler fail
import 'package:flutter/material.dart';
import 'package:web/web.dart' as web;
import 'package:dart_webrtc/dart_webrtc.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@jezell
jezell / o1-slides.dart
Created December 6, 2024 07:20
o1 pro slides from json test
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
class TextSlide {
/// Hex color for the text. Defaults to white (#ffffff) if missing or empty.
final String textColor;
/// Title of the slide. Defaults to empty string if missing.
final String title;
@jezell
jezell / graphite.md
Created December 6, 2024 07:42
Flutter Graphite

Note: Graphite is a relatively new and experimental GPU rendering backend within Skia, and as of now, Flutter does not officially support it out-of-the-box. Integrating Graphite into Flutter involves building a custom Flutter engine with the appropriate Skia flags enabled. The process below assumes familiarity with building the Flutter engine from source and working with GN/Ninja build systems.

Prerequisites:

  1. A working Flutter engine development environment:
  2. A platform that supports Graphite’s current GPU backends (e.g., Metal on macOS/iOS or Dawn on certain platforms).

@jezell
jezell / bug.md
Created December 6, 2024 07:50
Fix this bug

Issue Explanation

The reported error involves a runtime crash when the vector_graphics package attempts to draw an <image> element from an SVG. The stack trace suggests a TypeError is happening during onDrawImage, likely due to the decoding of image bytes into a Dart/Flutter UI image object not producing the expected type.

Prior to Flutter 3.10, decodeImageFromList was the conventional method to decode images from byte arrays. However, with updated Flutter versions and web compatibility changes, decodeImageFromList on the web may not return the expected ui.Image type, causing type errors at runtime. Instead, it's recommended to use the newer image decoding approach that involves ImmutableBuffer, ImageDescriptor, and Codec.

Root Cause

  • The onDrawImage method in FlutterVectorGraphicsListener is expecting a ui.Image, but the decoding method used might be returning something else or failing silently, leading to a TypeError.
  • If the code previously relied on `decodeImageFrom