Skip to content

Instantly share code, notes, and snippets.

@AlexV525
Created April 28, 2022 03:15
Show Gist options
  • Select an option

  • Save AlexV525/1024a9f5130a271f295fced171c1afde to your computer and use it in GitHub Desktop.

Select an option

Save AlexV525/1024a9f5130a271f295fced171c1afde to your computer and use it in GitHub Desktop.
None (same as `nil`, but named `None`)
///
/// [Author] Alex (https://github.com/AlexV525)
/// [Date] 2022/04/28 11:12
///
import 'package:flutter/widgets.dart';
const None none = None();
class None extends Widget {
const None({Key? key}) : super(key: key);
@override
Element createElement() => _NoneElement(this);
}
class _NoneElement extends Element {
_NoneElement(Widget widget) : super(widget);
@override
bool get debugDoingBuild => false;
@override
void mount(Element? parent, dynamic newSlot) {
assert(
parent is! MultiChildRenderObjectElement,
'You are using None under a MultiChildRenderObjectElement. '
'This suggests a possibility that the None '
'is not needed or is being used improperly. '
"Make sure it can't be replaced with an inline conditional or "
'omission of the target widget from a list.',
);
super.mount(parent, newSlot);
}
@override
void performRebuild() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment