Skip to content

Instantly share code, notes, and snippets.

View loic-sharma's full-sized avatar
🌴

Loïc Sharma loic-sharma

🌴
View GitHub Profile
@loic-sharma
loic-sharma / main.dart
Created April 30, 2026 18:28
Disable interactive selection
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: MinimalSelectionApp()));
class MinimalSelectionApp extends StatelessWidget {
const MinimalSelectionApp({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
@loic-sharma
loic-sharma / main.dart
Created April 30, 2026 18:22
Autofill test app
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MaterialApp(home: RegisterScreen()));
class RegisterScreen extends StatelessWidget {
const RegisterScreen({super.key});
@override
Widget build(BuildContext context) {
@loic-sharma
loic-sharma / README.md
Last active March 24, 2026 18:29
Code excerpts for API references

Proposal: Markdown Code Excerpts for API References

Overview

Currently, the Flutter framework uses snippet blocks in API reference docs to showcase example code. We are considering switching to Markdown code blocks.

To ensure these these examples don't "bit rot", we can use "code excerpts" to synchronize the examples to validated test files.

The workflow

@loic-sharma
loic-sharma / main.dart
Last active March 23, 2026 20:25
FocusNode.canRequestFocus remains true even after a route is pushed
// Steps:
//
// 1. Run this on DartPad: https://dartpad.dev/?id=3e371f0b26afde168837164ba3a1ef39
// 2. This shows Page One, which has a text field with a `FocusNode`.
// 2. Press **Push Page Two**. Page One and its text field are no longer visible or interactable.
// 3. Press **Print Page One status**.
//
// Expected behavior: Page One's `FocusNode` and `FocusScopeNode` are NOT focusable.
// Actual behavior: Page One's `FocusNode` and `FocusScopeNode` are focusable.
import 'package:flutter/material.dart';
class _MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [
ExpensiveWidget(focusNode: _node),
StateBuilder<double>(
create: (BuildContext context) => 1.0,
builder: (BuildContext context, double opacity, SetStateCallback<double> setOpacity) {
return GestureDetector(
@loic-sharma
loic-sharma / main.dart
Created February 4, 2026 18:37
SizedBox's layout behavior with incompatible constraints
import 'package:flutter/widgets.dart';
void main() {
final tight_200x200 = BoxConstraints.tight(Size(200, 200));
final tight_100x100 = BoxConstraints.tight(Size(100, 100));
final loose_0x0_to_200x200 = BoxConstraints.loose(Size(200, 200));
// Mimic this example:
//
// SizeBox(
@loic-sharma
loic-sharma / main.dart
Last active December 29, 2025 19:47
Sliding square using explicit animation
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: SlidingSquarePage()));
}
class SlidingSquarePage extends StatefulWidget {
const SlidingSquarePage({super.key});
@override
@loic-sharma
loic-sharma / main.dart
Last active December 29, 2025 19:41
Sliding using RepeatingAnimationBuilder
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: SlidingSquarePage()));
}
class SlidingSquarePage extends StatelessWidget {
const SlidingSquarePage({super.key});
@override
@loic-sharma
loic-sharma / README.md
Last active December 27, 2025 21:14
Inherited value

InheritedValue

Before After
@loic-sharma
loic-sharma / main.dart
Last active December 26, 2025 18:47
Dot shorthands error on map
enum MyEnum {
value1,
value2,
}
void foo() {
// Works as expected!
final Map<MyEnum, String> myMap = <MyEnum, String>{
MyEnum.value1: 'First',
.value2: 'Second',