Neu constructor

const Neu({
  1. Color color = lightWhite,
  2. int depth = defaultDepth,
  3. double spread = defaultSpread,
  4. Curvature curvature = Curvature.convex,
  5. Swell swell = Swell.emboss,
  6. Alignment lightSource = defaultLightSource,
  7. NeuTextSpec neuTextSpec = const NeuTextSpec(),
  8. BorderRadius borderRadius = BorderRadius.zero,
  9. ShapeBorder shape = defaultShape,
})

A Neumorphic, or new skeuomorphic, helper class with a variety of static and instance methods for the simple generation of shaded decorations conforming to the neumorphic design concept.

These designs are often solid in terms of color variety: genreally a dominant color is used as a backdrop as well as the color of controls and elements. These items that typically appear on or "above" the surface in standard design systems are intended in neumorphism to extrude from or "rise out" or into the surface.

This extrusion, which can be imagined as clay- or rubber-like, is achieved by a combination of same-color elements and background, contrasting shadows, slight variances in color shading and (potentially) gradients for the impression of natural lighting.


This class may be used to construct new Neu or new Neu.toggle objects. These objects will utilize their constructor arguments to fill static method arguments as easy storage and access or rapid redeployment.

Getter methods on new Neu instantiated objects:

Using a Neu Object

// final neuObject = Neu.toggle(
final neuObject = Neu(
  color: Colors.red,
  depth: 25,
  spread: 10,

  /// These parameters (curvature and swell) for `Neu.toggle` are handled
  /// dynamically by the below flags.
  curvature: Curvature.flat,
  swell: Swell.emboss,

  /// These flags are only valid for `Neu.toggle` where they drive the
  /// curvature and swell based on true or false states.
  // isToggled: isToggled,
  // isFlat: true,
  // isSuper: true,

  lightSource: Alignment.topLeft,
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(3.0),
    // side: BorderSide(width: 0.5, color: color.withWhite(10)),
    // side: BorderSide(width: 0.5, color: color),
  ),
);

This Neu object may then, for example, be used to generate a ShapeDecoration like so:

final neuContainer = Container(
  decoration: neuObject.buildShapeDecoration,
);

SEE ALSO:


NEUMORPHIC DEFINITION

Principal

With all Neu design the basis of these decorations is a color and a depth. Color should ideally match or be similar to the color of the background behind the resulting decoration. The depth is the extent to which this decoration will appear "extruded" from its surface. A larger depth increases the contrast of the shading of colors on either side of the decoration.

Appearance of Shape

Other customizations include curvature and swell, as well as an overriding lightSource represented as an Alignment.

A Curvature is a description of the appearance of the actual surface of the decoration. A Curvature.flat decoration has no gradient (solid-color Gradient), while Curvature.convex orders a light -> dark gradient in a way that inspires a "bubble"-like appearance.

(Other options make the effect more extreme, such as Curvature.superconvex or reverse the effect: Curvature.concave.)

A Swell is an overall depiction of how the decoration appears in terms of being inset into the surface or extruded from it.

This property, especially when combined with varying Curvatures can really "sell" the pressed or unpressed effect.

Override Source of "Light"

The lightSource is always set by default as defaultLightSource, which is Alignment.topLeft. This gives the illusion of lighting the entire neumorphic decoration from the top-left corner. All descriptions of gradient and shadow directionality and the illusion of being toggled or not toggled are based on this default light source. An overriding Alignment may be provided, however, to dynamically "relight" the decorations.

  • Consider this lighting entirely artificial. Aspects of real light physics are not recreated. Simply put, this value is used to offset/shift the light and dark shadows.

Softness of Shadows

In terms of Shadows, the argument spread is responsible for determining how wide an area the effect covers and how blurry the shadows appear.

Not all methods consider spread, notably linearGradient (and buildLinearGradient by extension) create a decoration (a LinearGradient) that does not have shadows. These gradients may be combined with shadows in other situations, where spread will then be considered.

Implementation

const Neu({
  this.color = lightWhite,
  this.depth = defaultDepth,
  this.spread = defaultSpread,
  this.curvature = Curvature.convex,
  this.swell = Swell.emboss,
  this.lightSource = defaultLightSource,
  this.neuTextSpec = const NeuTextSpec(),
  this.borderRadius = BorderRadius.zero,
  this.shape = defaultShape,
})  :
      // See [Neu.toggle] named constructor
      _isToggled = null,
      _isFlat = null,
      _isSuper = null,
      _depthMultiplier = null,
      _spreadMultiplier = null;