NsfwGuardWidget class
A widget that automatically scans media for NSFW content and either displays it normally or applies a protective overlay.
By default, the widget shows:
- A loading indicator while scanning
- The media normally if it's safe
- A blurred overlay with a warning icon if it's NSFW
- An error icon if scanning fails
All default states can be overridden with custom builders.
NsfwGuardWidget(
mediaFile: myImageFile,
child: Image.file(myImageFile), // The content to protect
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- NsfwGuardWidget
Constructors
-
NsfwGuardWidget.bytes({Key? key, required List<
int> bytes, required Widget child, NsfwGuardTheme? theme, double? threshold, WidgetBuilder? loadingBuilder, Widget safeBuilder(BuildContext context, Widget child)?, WidgetBuilder? unsafeBuilder, Widget errorBuilder(BuildContext context, Object error)?, ValueChanged<ScanResult> ? onScanComplete}) -
Scan raw image bytes in memory.
const
-
NsfwGuardWidget.file({Key? key, required File mediaFile, required Widget child, NsfwGuardTheme? theme, double? threshold, WidgetBuilder? loadingBuilder, Widget safeBuilder(BuildContext context, Widget child)?, WidgetBuilder? unsafeBuilder, Widget errorBuilder(BuildContext context, Object error)?, ValueChanged<
ScanResult> ? onScanComplete}) -
Scan a local File.
const
-
NsfwGuardWidget.provider({Key? key, required ImageProvider<
Object> imageProvider, required Widget child, NsfwGuardTheme? theme, double? threshold, WidgetBuilder? loadingBuilder, Widget safeBuilder(BuildContext context, Widget child)?, WidgetBuilder? unsafeBuilder, Widget errorBuilder(BuildContext context, Object error)?, ValueChanged<ScanResult> ? onScanComplete}) -
Scan an ImageProvider, resolving it asynchronously.
Excellent for compatibility with cached_network_image.
const
Properties
- child → Widget
-
The child widget to display (typically an Image widget).
This is the content that will be protected by the guard.
final
- errorBuilder → Widget Function(BuildContext context, Object error)?
-
Custom builder for the error state.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loadingBuilder → WidgetBuilder?
-
Custom builder for the loading state.
final
-
onScanComplete
→ ValueChanged<
ScanResult> ? -
Called when the scan completes with the result.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- safeBuilder → Widget Function(BuildContext context, Widget child)?
-
Custom builder for the safe state. Receives the child widget.
final
- theme → NsfwGuardTheme?
-
Optional theme override for this specific widget.
Falls back to FlutterNsfwDetector.defaultTheme if not provided.
final
- threshold → double?
-
Optional NSFW confidence threshold (0.0 - 1.0).
Defaults to FlutterNsfwDetector.defaultThreshold.
final
- unsafeBuilder → WidgetBuilder?
-
Custom builder for the unsafe/NSFW state.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< NsfwGuardWidget> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited