Skip to content

Commit

Permalink
fix: Optimize theme and shape.
Browse files Browse the repository at this point in the history
  • Loading branch information
GSMLG-BOT committed Aug 10, 2023
1 parent 7a051a4 commit adc9b7c
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 86 deletions.
80 changes: 0 additions & 80 deletions packages/material_neumorphic_theme/lib/src/colors.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NeumorphicEmbossPainterCache
@override
Color generateShadowDarkColor(
{required Color color, required double intensity}) {
return NeumorphicColors.embossDarkColor(
return NeumorphicTheme.embossDarkColor(

Check failure on line 11 in packages/material_neumorphic_theme/lib/src/decoration/cache/neumorphic_emboss_painter_cache.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'NeumorphicTheme'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
color,
intensity: intensity,
);
Expand All @@ -17,7 +17,7 @@ class NeumorphicEmbossPainterCache
@override
Color generateShadowLightColor(
{required Color color, required double intensity}) {
return NeumorphicColors.embossWhiteColor(
return NeumorphicTheme.embossWhiteColor(

Check failure on line 20 in packages/material_neumorphic_theme/lib/src/decoration/cache/neumorphic_emboss_painter_cache.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'NeumorphicTheme'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
color,
intensity: intensity,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class NeumorphicPainterCache extends AbstractNeumorphicEmbossPainterCache {
@override
Color generateShadowDarkColor(
{required Color color, required double intensity}) {
return NeumorphicColors.decorationDarkColor(color, intensity: intensity);
return NeumorphicTheme.decorationDarkColor(color, intensity: intensity);

Check failure on line 10 in packages/material_neumorphic_theme/lib/src/decoration/cache/neumorphic_painter_cache.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'NeumorphicTheme'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
}

@override
Color generateShadowLightColor(
{required Color color, required double intensity}) {
return NeumorphicColors.decorationWhiteColor(color, intensity: intensity);
return NeumorphicTheme.decorationWhiteColor(color, intensity: intensity);

Check failure on line 16 in packages/material_neumorphic_theme/lib/src/decoration/cache/neumorphic_painter_cache.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'NeumorphicTheme'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Shader getGradientShader(
begin: Alignment(source.dx, source.dy),
end: Alignment(sourceInvert.dx, sourceInvert.dy),
colors: <Color>[
NeumorphicColors.gradientShaderDarkColor(intensity: currentIntensity),
NeumorphicColors.gradientShaderWhiteColor(
NeumorphicTheme.gradientShaderDarkColor(intensity: currentIntensity),

Check failure on line 18 in packages/material_neumorphic_theme/lib/src/decoration/neumorphic_box_decoration_helper.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'NeumorphicTheme'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
NeumorphicTheme.gradientShaderWhiteColor(

Check failure on line 19 in packages/material_neumorphic_theme/lib/src/decoration/neumorphic_box_decoration_helper.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'NeumorphicTheme'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
intensity: currentIntensity * (2 / 5)),
],
stops: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'neumorphic_path_provider.dart';
import 'dart:math' as math;

@immutable
class BeveledPathProvider extends NeumorphicPathProvider {
final BorderRadius borderRadius;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';

import 'neumorphic_path_provider.dart';

@immutable
class CirclePathProvider extends NeumorphicPathProvider {
const CirclePathProvider({Listenable? reclip});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import '../neumorphic_path_provider.dart';

@immutable
class NeumorphicFlutterLogoPathProvider extends NeumorphicPathProvider {
@override
bool shouldReclip(NeumorphicPathProvider oldClipper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'neumorphic_path_provider.dart';

@immutable
class RectPathProvider extends NeumorphicPathProvider {
const RectPathProvider({Listenable? reclip});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'neumorphic_path_provider.dart';

@immutable
class RRectPathProvider extends NeumorphicPathProvider {
final BorderRadius borderRadius;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'rrect_path_provider.dart';

@immutable
class StadiumPathProvider extends RRectPathProvider {
const StadiumPathProvider({Listenable? reclip})
: super(
Expand Down
55 changes: 55 additions & 0 deletions packages/material_neumorphic_theme/lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,61 @@ class NeumorphicTheme extends ThemeExtension<NeumorphicTheme> {
static const double minCurve = 0.0;
static const double maxCurve = 1.0;

static const Color _gradientShaderDarkColor = Color(0x8A000000);
static const Color _gradientShaderWhiteColor = Color(0xFFFFFFFF);

static Color decorationWhiteColor(Color color, {required double intensity}) {
// intensity act on opacity;
return _applyPercentageOnOpacity(
maxColor: color,
percent: intensity,
);
}

static Color decorationDarkColor(Color color, {required double intensity}) {
// intensity act on opacity;
return _applyPercentageOnOpacity(
maxColor: color,
percent: intensity,
);
}

static Color embossWhiteColor(Color color, {required double intensity}) {
// intensity act on opacity;
return _applyPercentageOnOpacity(
maxColor: color,
percent: intensity,
);
}

static Color embossDarkColor(Color color, {required double intensity}) {
// intensity act on opacity;
return _applyPercentageOnOpacity(
maxColor: color,
percent: intensity,
);
}

static Color gradientShaderDarkColor({required double intensity}) {
// intensity act on opacity;
return _applyPercentageOnOpacity(
maxColor: _gradientShaderDarkColor, percent: intensity);
}

static Color gradientShaderWhiteColor({required double intensity}) {
// intensity act on opacity;
return _applyPercentageOnOpacity(
maxColor: _gradientShaderWhiteColor, percent: intensity);
}

static Color _applyPercentageOnOpacity(
{required Color maxColor, required double percent}) {
final maxOpacity = maxColor.opacity;
final newOpacity = percent * maxOpacity / maxIntensity;
final newColor = maxColor.withOpacity(newOpacity);
return newColor;
}

final Color? _baseColor;
final Color? _accentColor;
final Color? _variantColor;
Expand Down

0 comments on commit adc9b7c

Please sign in to comment.