Skip to content

Instantly share code, notes, and snippets.

View mdebbar's full-sized avatar

Mouad Debbar mdebbar

View GitHub Profile
@mdebbar
mdebbar / main.dart
Last active October 18, 2024 20:11
Showcases a problem with the default hit test behavior on Platform Views
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
final List<Color> colors = <Color>[
Colors.blue,
Colors.red,
Colors.green,
Colors.purple,
Colors.orange,
@mdebbar
mdebbar / js_api.js
Created November 4, 2022 20:34
JS API to be used with ICU4X
function getLineBreaks(text) {
// Returns a list of indices of line breaks in the
// text along with the type of each break (soft or hard).
}
function getBidiRegions(text) {
// Returns a list of BiDi regions, where each region contains:
// 1. A range (start and end).
// 2. BiDi level.
}
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
@mdebbar
mdebbar / FLUTTER WEB: TEXT LAYOUT.md
Last active June 29, 2022 19:22
High level description of how text layout is done in Flutter Web; and where we are falling short and need browsers' help with new APIs.

This is a high level overview of how we do text layout and rendering in Flutter Web:

Fragmenting

Before we start measuring text, we first need to break it down into fragments. A fragment is the longest substring in the paragraph that satisfies the following:

  1. Contains no soft or hard line breaks.
  2. The entire fragment has the same text direction.
  3. The entire fragment has the same text style.

1. Line breaks

@mdebbar
mdebbar / router.dart
Created March 13, 2020 07:08
Combining route name parser with router delegate.
abstract class RoutingConfig {
RouteParsingResult parseRouteName(String routeName);
Widget build(BuildContext context);
}
class RouteParsingResult {
RouteParsingResult({});
/// The part of the route name that was matched/consumed by this routing node.
@mdebbar
mdebbar / main.dart
Created February 20, 2020 23:54
List<PointerEvent> is a List<dynamic>
import 'dart:html';
void main() {
window.addEventListener('pointermove', handlePointerMove);
}
void handlePointerMove(Event event) {
final PointerEvent pointerEvent = event;
final Iterable<Foo> fooList = expandEvent(pointerEvent).expand(
(PointerEvent e) => getFooListForEvent(e),
bool foo() {
Future.value(10).then((_) {
return true;
}).catchError((_) {
return false;
});
}
void main() {
print(foo());
@mdebbar
mdebbar / main.dart
Created May 28, 2019 21:27
Repro for wrong runtimeType
void main() {
final double x = 10.0;
print(x.runtimeType); // Prints "int"
}
@mdebbar
mdebbar / main.dart
Created April 3, 2019 19:36
Analyzer - switch exhaustiveness
enum MyEnum {
e1,
e2,
e3,
}
String getString(MyEnum value) {
switch (value) {
case MyEnum.e1:
return 'e1';
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Component.extend({
tagName: '',
text: computed.oneWay('todo.text'),
json: computed('todo.{id,text}', function() {
return JSON.stringify(this.get('todo'));
}),