Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Champigny committed May 5, 2020
1 parent 3dccbfb commit 9c9a223
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 60 deletions.
21 changes: 11 additions & 10 deletions example/.firebase/hosting.YnVpbGQvd2Vi.cache
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
favicon.png,1584519147904,fcc7c4545d5b62ad01682589e6fdc7ea03d0a3b42069963c815c344b632eb5cf
index.html,1583874829522,810de61ef287305f760d2ec6fbc6fe99d77b6c4563eb498ec9d8ec03225b223c
manifest.json,1583874829523,45d760140cc6ca5c7e0a784028d3e3677134020394b8275b8572098634a57cdc
assets/assets/images/concave.png,1586104731636,933ec2a0e42afcbc358d014683aef7409803579ee9c2062ba21bae43f129c145
assets/assets/images/convex.png,1586104731637,e464bf89d64c9811b9bfe8128499a6cf334175378527d67af7318fd989b5aa67
assets/assets/images/credit_card_chip.png,1583153326739,87e0e2d3872b3cbd52aacccbe03bfe779fefeb207ddb3458e3680ef99d784d1b
assets/assets/images/flat.png,1586104731637,883adca79d11f13ecd7a72e2277dce30ba8359526d5419c177e464d26112b368
assets/assets/images/map.jpg,1583153326740,820ca10f11e4612328f85a2a86d00f0b52797c763b334ad656457545a825932c
assets/assets/images/tesla.png,1583758820000,237196b6c1eae268725d18581847e3dadeb1b1b5d7947a26268d9f3d7d45e366
assets/assets/images/tesla_cropped.png,1583767348771,27e96ada195e6fad9a507f3e2323b6c2d2ee57fad8490e16c7b6e57e17821394
assets/assets/images/weeknd.jpg,1583253568570,8185c2982531501772a16ee48a1211b728636258b0f07995bd73bf20781b92ec
assets/fonts/MaterialIcons-Regular.ttf,1475244374000,49f9a5d2c31ecd331d178c6c3d587181ce635721e46240a8547f0a5374f3257d
assets/fonts/SamsungSans-Bold.ttf,1586032911302,74ff7c45e5857e735137162868d2bc9340014970ed25cab3d3eda809082c65b3
icons/Icon-192.png,1583873961501,d2e0131bb7851eb9d98f7885edb5ae4b4d6b7a6c7addf8a25b9b712b39274c0f
icons/Icon-512.png,1583873961501,7a31ce91e554f1941158ca46f31c7f3f2b7c8c129229ea74a8fae1affe335033
assets/AssetManifest.json,1587558871062,92389c3c6690ae83b58860b31298c42afd6910d11bc17a45bfb903d5d815d6e8
flutter_service_worker.js,1587558871502,7b77fb9bf445cffaf7ad0722127ad8acb3150d5575d8d89fcdba8895a9009baf
assets/FontManifest.json,1587558871062,fa35eb9e57e1a2f9c0d1b158b9da9a619c165144e2681e47bb6ac24af99bd364
assets/assets/images/concave.png,1586104731636,933ec2a0e42afcbc358d014683aef7409803579ee9c2062ba21bae43f129c145
assets/assets/images/convex.png,1586104731637,e464bf89d64c9811b9bfe8128499a6cf334175378527d67af7318fd989b5aa67
assets/assets/images/flat.png,1586104731637,883adca79d11f13ecd7a72e2277dce30ba8359526d5419c177e464d26112b368
assets/fonts/SamsungSans-Bold.ttf,1586032911302,74ff7c45e5857e735137162868d2bc9340014970ed25cab3d3eda809082c65b3
assets/LICENSE,1587558871063,c4cb7261eb0fadaefe6ca5bae616cba10e04b902bb601ae16668abeb40cad74c
main.dart.js,1587558868395,cda87c962e806b717c809ab2778e371aa0149d06d7228640095048f362e09859
main.dart.js.map,1587558868704,e1afaf8499b0a0325ac0a2af2e284bdd5fde56885cc065030fad95fb930d1475
assets/FontManifest.json,1588702040192,d1ca17477205b8d6f669d7b468e1f2a2488d9f284a33d5e78d10ce5da507808c
assets/AssetManifest.json,1588702040192,18282352e656d5f790f06bed5bf4c625149b1707aa0806db310d96415c13e811
flutter_service_worker.js,1588702040700,23198abff98ee787d21842f13805595888da4d316e83c23265ffc8e8c86cf087
assets/packages/flutter_neumorphic/fonts/NeumorphicIcons.ttf,1588237285784,c119c0add3500d279f98593b0cf1deb3ea25cc1a6029421764392733e5e778a1
assets/LICENSE,1588702040193,c4cb7261eb0fadaefe6ca5bae616cba10e04b902bb601ae16668abeb40cad74c
main.dart.js,1588702039105,ffcb5aa97926d1f3711d3cf7d68e5e97735d6f99d353c2276a07e84725406060
main.dart.js.map,1588702039479,d3bf63fb2e43fe08594852a8386f5ea0a099c8837896f823360177ccf5764f66
1 change: 0 additions & 1 deletion lib/src/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ class NeumorphicColors {
maxColor.withOpacity(newOpacity); //<-- intensity act on opacity;
return newColor;
}

}
30 changes: 14 additions & 16 deletions lib/src/decoration/neumorphic_decoration_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ class NeumorphicDecorationPainter extends BoxPainter {
void generatePainters() {
this._backgroundPaint = Paint();
this._whiteShadowPaint = Paint();
this._whiteShadowMaskPaint = Paint()
..blendMode = BlendMode.dstOut;
this._whiteShadowMaskPaint = Paint()..blendMode = BlendMode.dstOut;
this._blackShadowPaint = Paint();
this._blackShadowMaskPaint = Paint()
..blendMode = BlendMode.dstOut;
this._blackShadowMaskPaint = Paint()..blendMode = BlendMode.dstOut;
this._gradientPaint = Paint();

this._borderPaint = Paint()
Expand Down Expand Up @@ -62,7 +60,7 @@ class NeumorphicDecorationPainter extends BoxPainter {
}

final bool invalidateSize =
this._cache.updateSize(newOffset: offset, newSize: configuration.size);
this._cache.updateSize(newOffset: offset, newSize: configuration.size);
if (invalidateSize) {
_cache.updatePath(
newPath: shape.customShapePathProvider.getPath(configuration.size));
Expand All @@ -83,10 +81,10 @@ class NeumorphicDecorationPainter extends BoxPainter {
}

final bool invalidateShadowColors = this._cache.updateShadowColor(
newShadowLightColorEmboss: style.shadowLightColor,
newShadowDarkColorEmboss: style.shadowDarkColor,
newIntensity: style.intensity,
);
newShadowLightColorEmboss: style.shadowLightColor,
newShadowDarkColorEmboss: style.shadowDarkColor,
newIntensity: style.intensity,
);
if (invalidateShadowColors) {
_whiteShadowPaint..color = _cache.shadowLightColor;
_blackShadowPaint..color = _cache.shadowDarkColor;
Expand Down Expand Up @@ -115,8 +113,7 @@ class NeumorphicDecorationPainter extends BoxPainter {
for (var subPath in _cache.subPaths) {
_drawElement(offset: offset, canvas: canvas, path: subPath);
}
}
else {
} else {
_drawElement(offset: offset, canvas: canvas, path: _cache.path);
}
}
Expand All @@ -134,14 +131,15 @@ class NeumorphicDecorationPainter extends BoxPainter {
}

void _drawBorder({Canvas canvas, Offset offset, Path path}) {
if(style.border.width > 0) {
if (style.border.width > 0) {
canvas
..save()
..translate(offset.dx, offset.dy)
..drawPath(path, _borderPaint
..color = style.border.color ?? Color(0x00000000)
..strokeWidth = style.border.width ?? 0
)
..drawPath(
path,
_borderPaint
..color = style.border.color ?? Color(0x00000000)
..strokeWidth = style.border.width ?? 0)
..restore();
}
}
Expand Down
11 changes: 6 additions & 5 deletions lib/src/decoration/neumorphic_emboss_decoration_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ class NeumorphicEmbossDecorationPainter extends BoxPainter {
}

void _drawBorder({Canvas canvas, Offset offset, Path path}) {
if(style.border.width > 0) {
if (style.border.width > 0) {
canvas
..save()
..translate(offset.dx, offset.dy)
..drawPath(path, _borderPaint
..color = style.border.color ?? Color(0x00000000)
..strokeWidth = style.border.width ?? 0
)
..drawPath(
path,
_borderPaint
..color = style.border.color ?? Color(0x00000000)
..strokeWidth = style.border.width ?? 0)
..restore();
}
}
Expand Down
58 changes: 40 additions & 18 deletions lib/src/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class NeumorphicThemeData {
double get depth => _depth?.clamp(Neumorphic.MIN_DEPTH, Neumorphic.MAX_DEPTH);

/// Get this theme's intensity, clamp to min/max neumorphic constants
double get intensity => _intensity?.clamp(Neumorphic.MIN_INTENSITY, Neumorphic.MAX_INTENSITY);
double get intensity =>
_intensity?.clamp(Neumorphic.MIN_INTENSITY, Neumorphic.MAX_INTENSITY);

const NeumorphicThemeData({
this.baseColor = _defaultBaseColor,
Expand Down Expand Up @@ -175,8 +176,10 @@ class NeumorphicThemeData {
disableDepth: disableDepth ?? this.disableDepth,
shadowDarkColor: shadowDarkColor ?? this.shadowDarkColor,
shadowLightColor: shadowLightColor ?? this.shadowLightColor,
shadowDarkColorEmboss: shadowDarkColorEmboss ?? this.shadowDarkColorEmboss,
shadowLightColorEmboss: shadowLightColorEmboss ?? this.shadowLightColorEmboss,
shadowDarkColorEmboss:
shadowDarkColorEmboss ?? this.shadowDarkColorEmboss,
shadowLightColorEmboss:
shadowLightColorEmboss ?? this.shadowLightColorEmboss,
depth: depth ?? this._depth,
borderWidth: borderSize ?? this.borderWidth,
borderColor: borderColor ?? this.borderColor,
Expand All @@ -199,8 +202,10 @@ class NeumorphicThemeData {
defaultTextColor: other.defaultTextColor ?? this.defaultTextColor,
shadowDarkColor: other.shadowDarkColor ?? this.shadowDarkColor,
shadowLightColor: other.shadowLightColor ?? this.shadowLightColor,
shadowDarkColorEmboss: other.shadowDarkColorEmboss ?? this.shadowDarkColorEmboss,
shadowLightColorEmboss: other.shadowLightColorEmboss ?? this.shadowLightColorEmboss,
shadowDarkColorEmboss:
other.shadowDarkColorEmboss ?? this.shadowDarkColorEmboss,
shadowLightColorEmboss:
other.shadowLightColorEmboss ?? this.shadowLightColorEmboss,
depth: other.depth ?? this._depth,
borderColor: other.borderColor ?? this.borderColor,
borderWidth: other.borderWidth ?? this.borderWidth,
Expand Down Expand Up @@ -236,7 +241,12 @@ class NeumorphicBorder {

@override
bool operator ==(Object other) =>
identical(this, other) || other is NeumorphicBorder && runtimeType == other.runtimeType && isEnabled == other.isEnabled && color == other.color && width == other.width;
identical(this, other) ||
other is NeumorphicBorder &&
runtimeType == other.runtimeType &&
isEnabled == other.isEnabled &&
color == other.color &&
width == other.width;

@override
int get hashCode => isEnabled.hashCode ^ color.hashCode ^ width.hashCode;
Expand All @@ -246,22 +256,26 @@ class NeumorphicBorder {
return 'NeumorphicBorder{isEnabled: $isEnabled, color: $color, width: $width}';
}

static NeumorphicBorder lerp(NeumorphicBorder a, NeumorphicBorder b, double t) {
static NeumorphicBorder lerp(
NeumorphicBorder a, NeumorphicBorder b, double t) {
assert(t != null);

if (a == null && b == null) return null;

if (t == 0.0) return a;
if (t == 1.0) return b;

return NeumorphicBorder(color: Color.lerp(a.color, b.color, t), isEnabled: a.isEnabled, width: lerpDouble(a.width, b.width, t));
return NeumorphicBorder(
color: Color.lerp(a.color, b.color, t),
isEnabled: a.isEnabled,
width: lerpDouble(a.width, b.width, t));
}

NeumorphicBorder copyWithThemeIfNull({Color color, double width}) {
return NeumorphicBorder(
isEnabled: this.isEnabled,
color: this.color ?? color,
width: this.width ?? width,
color: this.color ?? color,
width: this.width ?? width,
);
}
}
Expand Down Expand Up @@ -334,20 +348,25 @@ class NeumorphicStyle {

double get depth => _depth?.clamp(Neumorphic.MIN_DEPTH, Neumorphic.MAX_DEPTH);

double get intensity => _intensity?.clamp(Neumorphic.MIN_INTENSITY, Neumorphic.MAX_INTENSITY);
double get intensity =>
_intensity?.clamp(Neumorphic.MIN_INTENSITY, Neumorphic.MAX_INTENSITY);

double get surfaceIntensity => _surfaceIntensity?.clamp(Neumorphic.MIN_INTENSITY, Neumorphic.MAX_INTENSITY);
double get surfaceIntensity => _surfaceIntensity?.clamp(
Neumorphic.MIN_INTENSITY, Neumorphic.MAX_INTENSITY);

NeumorphicStyle copyWithThemeIfNull(NeumorphicThemeData theme) {
return NeumorphicStyle._withTheme(
theme: theme,
color: this.color ?? theme.baseColor,
shape: this.shape,
border: this.border.copyWithThemeIfNull(color: theme.borderColor, width: theme.borderWidth),
border: this.border.copyWithThemeIfNull(
color: theme.borderColor, width: theme.borderWidth),
shadowDarkColor: this.shadowDarkColor ?? theme.shadowDarkColor,
shadowLightColor: this.shadowLightColor ?? theme.shadowLightColor,
shadowDarkColorEmboss: this.shadowDarkColorEmboss ?? theme.shadowDarkColorEmboss,
shadowLightColorEmboss: this.shadowLightColorEmboss ?? theme.shadowLightColorEmboss,
shadowDarkColorEmboss:
this.shadowDarkColorEmboss ?? theme.shadowDarkColorEmboss,
shadowLightColorEmboss:
this.shadowLightColorEmboss ?? theme.shadowLightColorEmboss,
depth: this.depth ?? theme.depth,
intensity: this.intensity ?? theme.intensity,
disableDepth: this.disableDepth ?? theme.disableDepth,
Expand Down Expand Up @@ -414,15 +433,18 @@ class NeumorphicStyle {
border: border ?? this.border,
shadowDarkColor: shadowDarkColor ?? this.shadowDarkColor,
shadowLightColor: shadowLightColor ?? this.shadowLightColor,
shadowDarkColorEmboss: shadowDarkColorEmboss ?? this.shadowDarkColorEmboss,
shadowLightColorEmboss: shadowLightColorEmboss ?? this.shadowLightColorEmboss,
shadowDarkColorEmboss:
shadowDarkColorEmboss ?? this.shadowDarkColorEmboss,
shadowLightColorEmboss:
shadowLightColorEmboss ?? this.shadowLightColorEmboss,
depth: depth ?? this.depth,
theme: this.theme,
intensity: intensity ?? this.intensity,
surfaceIntensity: surfaceIntensity ?? this.surfaceIntensity,
disableDepth: disableDepth ?? this.disableDepth,
lightSource: lightSource ?? this.lightSource,
oppositeShadowLightSource: oppositeShadowLightSource ?? this.oppositeShadowLightSource,
oppositeShadowLightSource:
oppositeShadowLightSource ?? this.oppositeShadowLightSource,
shape: shape ?? this.shape,
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/widget/container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ class _NeumorphicContainer extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTextStyle(
style: this.textStyle ?? material.Theme.of(context).textTheme.body2, //TODO migrate to textBody2
style: this.textStyle ??
material.Theme.of(context)
.textTheme
.body2, //TODO migrate to textBody2
child: AnimatedContainer(
margin: this.margin,
duration: this.duration,
Expand Down
11 changes: 5 additions & 6 deletions lib/src/widget/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,11 @@ class AnimatedThumb extends StatelessWidget {
child: Neumorphic(
boxShape: NeumorphicBoxShape.circle(),
style: NeumorphicStyle(
disableDepth: this.disableDepth,
shape: shape,
depth: this.depth,
color: thumbColor,
border: this.border
),
disableDepth: this.disableDepth,
shape: shape,
depth: this.depth,
color: thumbColor,
border: this.border),
child: AspectRatio(
aspectRatio: 1,
child: FractionallySizedBox(
Expand Down
17 changes: 14 additions & 3 deletions lib/src/widget/toggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class NeumorphicToggleStyle {
animateOpacity == other.animateOpacity;

@override
int get hashCode => depth.hashCode ^ backgroundColor.hashCode ^ border.hashCode ^ disableDepth.hashCode ^ borderRadius.hashCode ^ animateOpacity.hashCode;
int get hashCode =>
depth.hashCode ^
backgroundColor.hashCode ^
border.hashCode ^
disableDepth.hashCode ^
borderRadius.hashCode ^
animateOpacity.hashCode;
}

/// Direct child of NeumorphicToggle
Expand Down Expand Up @@ -221,11 +227,16 @@ class NeumorphicToggle extends StatelessWidget {
}

Widget _backgroundAtIndex(int index) {
return Expanded(flex: 1, child: this.children[index].background ?? SizedBox.expand());
return Expanded(
flex: 1, child: this.children[index].background ?? SizedBox.expand());
}

Widget _foregroundAtIndex(int index) {
Widget child = (!this.displayForegroundOnlyIfSelected) || (this.displayForegroundOnlyIfSelected && this.selectedIndex == index) ? this.children[index].foreground : SizedBox.expand();
Widget child = (!this.displayForegroundOnlyIfSelected) ||
(this.displayForegroundOnlyIfSelected &&
this.selectedIndex == index)
? this.children[index].foreground
: SizedBox.expand();
//wrap with opacity animation
if (style.animateOpacity) {
child = AnimatedOpacity(
Expand Down

0 comments on commit 9c9a223

Please sign in to comment.