Skip to content

Instantly share code, notes, and snippets.

View loic-sharma's full-sized avatar
🌴
On vacation until February 23!

Loïc Sharma loic-sharma

🌴
On vacation until February 23!
View GitHub Profile
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',
@loic-sharma
loic-sharma / README.md
Created December 16, 2025 20:59
APIs that use the ".of" pattern on a BuildContext
ActionIconTheme.of
Actions.of
AnimatedGrid.maybeOf
AnimatedGrid.of
AnimatedList.maybeOf
AnimatedList.of
AppBarTheme.of
AutocompleteHighlightedOption.of
AutofillGroup.maybeOf
final counter = signal(0);
final userProfile = signal({ 'name': 'Guest' });
final counterSquared = computed((context) {
final count = context.watch(counter);
return count * count;
})
final printEffect = effect((context) {
final count = context.watch(counter);
print('Counter changed to $count');
@loic-sharma
loic-sharma / README.md
Created November 21, 2025 18:01
Quantifying the demand to stop pinning the Flutter SDK's dependencies

Here is the activity on flutter/flutter#158050 in hte last 100 days (from 2025-08-13 to 2025-11-21):

Total reactions Total comments New reactions New comments
95 14 3 2

How to analyze this data yourself

  1. Install DuckDB.
@loic-sharma
loic-sharma / main.dart
Last active November 19, 2025 03:11
Style API
import 'package:flutter/material.dart';
void main() => runApp(const MyWidget());
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return const Column(