Skip to content

Instantly share code, notes, and snippets.

View letsar's full-sized avatar
🦋
Flutter forever

Romain Rastel letsar

🦋
Flutter forever
View GitHub Profile
@letsar
letsar / variable_sized_grid_view.dart
Last active January 31, 2023 22:54
VariableSizedGridView for Flutter (Masonry style)
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
/// Signature for a function that creates a [TileSize] for a given index.
typedef TileSize IndexedTileSizeBuilder(int index);
/// Creates grid layouts with a fixed number of spans in the cross axis.
@letsar
letsar / tab_bar_view.dart
Created June 30, 2018 12:31
How to use a SliverStickyHeader inside a TabBarView
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
class _Page {
const _Page(
this.id,
this.title,
this.color,
@letsar
letsar / ChangeNotifier.dart
Last active January 23, 2021 12:16
ChangeNotifier with List and queuing
typedef VoidCallback = void Function();
class ChangeNotifier {
List<VoidCallback> _listeners = List<VoidCallback>();
List<int> _toRemove = List<int>();
bool _notifying = false;
bool get hasListeners {
return _listeners.isNotEmpty;
}
@letsar
letsar / ChangeNotifier.dart
Last active November 13, 2020 02:29
A ChangeNotifier implementation using List
typedef VoidCallback = void Function();
class _Listener {
_Listener(this.func);
final VoidCallback func;
VoidCallback afterNotify;
void call() {
if (afterNotify == null) {
func();
}
@letsar
letsar / render_sliver_gap.dart
Created May 13, 2020 13:00
RenderSliverGap
class RenderSliverGap extends RenderSliver {
RenderSliverGap({
double mainAxisExtent,
}) : _mainAxisExtent = mainAxisExtent;
double get mainAxisExtent => _mainAxisExtent;
double _mainAxisExtent;
set mainAxisExtent(double value) {
if (_mainAxisExtent != value) {
_mainAxisExtent = value;
@letsar
letsar / sliver_geometry.dart
Created May 9, 2020 11:58
SliverGeometry constructor
const SliverGeometry({
this.scrollExtent = 0.0,
this.paintExtent = 0.0,
this.paintOrigin = 0.0,
double layoutExtent,
this.maxPaintExtent = 0.0,
this.maxScrollObstructionExtent = 0.0,
double hitTestExtent,
bool visible,
this.hasVisualOverflow = false,
@letsar
letsar / sliver_constraints.dart
Created May 9, 2020 06:04
SliverConstraints constructor
const SliverConstraints({
@required this.axisDirection,
@required this.growthDirection,
@required this.userScrollDirection,
@required this.scrollOffset,
@required this.precedingScrollExtent,
@required this.overlap,
@required this.remainingPaintExtent,
@required this.crossAxisExtent,
@required this.crossAxisDirection,
class Gap extends LeafRenderObjectWidget {
const Gap(
this.mainAxisExtent, {
Key key,
}) : assert(mainAxisExtent != null &&
mainAxisExtent >= 0 &&
mainAxisExtent < double.infinity),
super(key: key);
final double mainAxisExtent;
class _RenderGap extends RenderBox {
_RenderGap({
double mainAxisExtent,
}) : _mainAxisExtent = mainAxisExtent;
double get mainAxisExtent => _mainAxisExtent;
double _mainAxisExtent;
set mainAxisExtent(double value) {
if (_mainAxisExtent != value) {
_mainAxisExtent = value;
@letsar
letsar / gap_01.dart
Created May 6, 2020 13:13
Simple code for a Gap Widget
class Gap extends LeafRenderObjectWidget {
const Gap(
this.mainAxisExtent, {
Key key,
}) : assert(mainAxisExtent != null &&
mainAxisExtent >= 0 &&
mainAxisExtent < double.infinity),
super(key: key);
final double mainAxisExtent;