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 / 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;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
builder: (_) => ValueNotifier<String>(null),
/*
ModelBinding<T>: a simple class for binding a Flutter app to a immutable
model of type T.
This is a complete application. The app shows the state of an instance of
MyModel in a button's label, and replaces its MyModel instance when the
button is pressed.
ModelBinding is an inherited widget that must be created in a context above