Skip to content

Instantly share code, notes, and snippets.

Avatar
🦋
Flutter forever

Romain Rastel letsar

🦋
Flutter forever
View GitHub Profile
@letsar
letsar / ChangeNotifier.dart
Last active Jan 23, 2021
ChangeNotifier with List and queuing
View ChangeNotifier.dart
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 Nov 13, 2020
A ChangeNotifier implementation using List
View ChangeNotifier.dart
typedef VoidCallback = void Function();
class _Listener {
_Listener(this.func);
final VoidCallback func;
VoidCallback afterNotify;
void call() {
if (afterNotify == null) {
func();
}
View render_sliver_gap.dart
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
SliverGeometry constructor
View sliver_geometry.dart
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
SliverConstraints constructor
View sliver_constraints.dart
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,
View gap.dart
class Gap extends LeafRenderObjectWidget {
const Gap(
this.mainAxisExtent, {
Key key,
}) : assert(mainAxisExtent != null &&
mainAxisExtent >= 0 &&
mainAxisExtent < double.infinity),
super(key: key);
final double mainAxisExtent;
View render_gap.dart
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
Simple code for a Gap Widget
View gap_01.dart
class Gap extends LeafRenderObjectWidget {
const Gap(
this.mainAxisExtent, {
Key key,
}) : assert(mainAxisExtent != null &&
mainAxisExtent >= 0 &&
mainAxisExtent < double.infinity),
super(key: key);
final double mainAxisExtent;
View changenotifierprovider_example.dart
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),
View model_binding_demo.dart
/*
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