Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created June 24, 2025 16:04
Show Gist options
  • Save loic-sharma/2934cb37072875c8cb7d9d5b365274b5 to your computer and use it in GitHub Desktop.
Save loic-sharma/2934cb37072875c8cb7d9d5b365274b5 to your computer and use it in GitHub Desktop.
Primary constructor experiments
// Current
class Opacity extends SingleChildRenderObjectWidget {
/// Creates a widget that makes its child partially transparent.
///
/// The [opacity] argument must be between zero and one, inclusive.
const Opacity({
super.key,
required this.opacity,
this.alwaysIncludeSemantics = false,
super.child,
}) : assert(opacity >= 0.0 && opacity <= 1.0);
/// Lots of comments.
///
/// Lots of comments.
final double opacity;
/// Lots of comments
///
/// Lots of comments.
final bool alwaysIncludeSemantics;
...
}
// Using a primary header constructor
class const Opacity({
super.key,
/// Lots of comments.
///
/// Lots of comments.
required double opacity,
/// Lots of comments.
///
/// Lots of comments.
bool alwaysIncludeSemantics = false,
super.child,
}) : assert(opacity >= 0.0 && opacity <= 1.0)
extends SingleChildRenderObjectWidget {
}
// Using a primary body constructor
class Opacity extends SingleChildRenderObjectWidget {
/// Creates a widget that makes its child partially transparent.
///
/// The [opacity] argument must be between zero and one, inclusive.
const this({
super.key,
/// Lots of comments.
///
/// Lots of comments.
required double opacity,
/// Lots of comments.
///
/// Lots of comments.
bool alwaysIncludeSemantics = false,
super.child,
}) : assert(opacity >= 0.0 && opacity <= 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment