master #81
@ -66,84 +66,17 @@ class CardWrapper extends StatelessWidget {
|
|||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
|
|
||||||
Gradient? _cardGradient(BuildContext context) {
|
|
||||||
if (backgroundColors != null && backgroundColors!.isGradient) {
|
|
||||||
return LinearGradientHelper.fromMultiColor(backgroundColors!);
|
|
||||||
} else {
|
|
||||||
final extensionCardColor =
|
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
|
||||||
|
|
||||||
if (extensionCardColor != null &&
|
|
||||||
extensionCardColor.backgroundColors != null &&
|
|
||||||
extensionCardColor.backgroundColors!.isGradient) {
|
|
||||||
return LinearGradient(
|
|
||||||
colors: extensionCardColor.backgroundColors!.colors,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color? _cardColor(BuildContext context) {
|
|
||||||
if (backgroundColors != null && backgroundColors!.isColor) {
|
|
||||||
return backgroundColors!.color;
|
|
||||||
} else {
|
|
||||||
final extensionCardColor =
|
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
|
||||||
|
|
||||||
if (extensionCardColor != null &&
|
|
||||||
extensionCardColor.backgroundColors != null) {
|
|
||||||
return extensionCardColor.backgroundColors!.color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Theme.of(context).cardColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
BoxBorder? _boxBorder(BuildContext context) {
|
|
||||||
if (borderColors != null) {
|
|
||||||
if (borderColors!.isGradient) {
|
|
||||||
return GradientBoxBorder(
|
|
||||||
gradient: LinearGradientHelper.fromMultiColor(borderColors!),
|
|
||||||
);
|
|
||||||
} else if (borderColors!.isColor) {
|
|
||||||
return Border.all(
|
|
||||||
color: borderColors!.color,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final extensionCardColor =
|
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
|
||||||
if (extensionCardColor != null &&
|
|
||||||
extensionCardColor.borderColors != null) {
|
|
||||||
if (extensionCardColor.borderColors!.isGradient) {
|
|
||||||
return GradientBoxBorder(
|
|
||||||
gradient: LinearGradient(
|
|
||||||
colors: extensionCardColor.borderColors!.colors,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (extensionCardColor.backgroundColors!.colors.isNotEmpty) {
|
|
||||||
return Border.all(
|
|
||||||
color: extensionCardColor.backgroundColors!.color,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BoxShadow> _shadow(BuildContext context) {
|
List<BoxShadow> _shadow(BuildContext context) {
|
||||||
final shadows = List<BoxShadow>.empty(growable: true);
|
final themeShadow = ThemeHelper.getThemeElement<BoxShadow, BoxShadow>(
|
||||||
if (shadow != null) {
|
[
|
||||||
shadows.add(shadow!);
|
shadow,
|
||||||
} else {
|
Theme.of(context).extension<CardThemeExtension>()?.shadowColor,
|
||||||
final extensionCardColor =
|
],
|
||||||
Theme.of(context).extension<CardThemeExtension>();
|
valueValidator: (shadow) => shadow != null,
|
||||||
if (extensionCardColor != null &&
|
transform: (shadow) => shadow,
|
||||||
extensionCardColor.shadowColor != null) {
|
defaultValue: null,
|
||||||
shadows.add(extensionCardColor.shadowColor!);
|
);
|
||||||
}
|
return (themeShadow != null) ? [themeShadow] : [];
|
||||||
}
|
|
||||||
return shadows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -152,9 +85,53 @@ class CardWrapper extends StatelessWidget {
|
|||||||
key: _key,
|
key: _key,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
gradient: _cardGradient(context),
|
gradient: ThemeHelper.getThemeElement<MultiColor, Gradient>(
|
||||||
color: _cardColor(context),
|
[
|
||||||
border: _boxBorder(context),
|
backgroundColors,
|
||||||
|
Theme.of(context)
|
||||||
|
.extension<CardThemeExtension>()
|
||||||
|
?.backgroundColors,
|
||||||
|
],
|
||||||
|
valueValidator: (multiColor) =>
|
||||||
|
multiColor != null && multiColor.isGradient,
|
||||||
|
transform: (multiColor) =>
|
||||||
|
LinearGradientHelper.fromMultiColor(multiColor!),
|
||||||
|
defaultValue: null,
|
||||||
|
),
|
||||||
|
color: ThemeHelper.getThemeElement<MultiColor, Color>(
|
||||||
|
[
|
||||||
|
backgroundColors,
|
||||||
|
Theme.of(context)
|
||||||
|
.extension<CardThemeExtension>()
|
||||||
|
?.backgroundColors,
|
||||||
|
],
|
||||||
|
valueValidator: (multiColor) =>
|
||||||
|
multiColor != null && multiColor.isColor,
|
||||||
|
transform: (multiColor) => multiColor?.color,
|
||||||
|
defaultValue: Theme.of(context).cardColor,
|
||||||
|
),
|
||||||
|
border: ThemeHelper.getThemeElement<MultiColor, BoxBorder>(
|
||||||
|
[
|
||||||
|
borderColors,
|
||||||
|
Theme.of(context).extension<CardThemeExtension>()?.borderColors,
|
||||||
|
Theme.of(context)
|
||||||
|
.extension<CardThemeExtension>()
|
||||||
|
?.backgroundColors,
|
||||||
|
],
|
||||||
|
valueValidator: (multiColor) =>
|
||||||
|
multiColor != null && multiColor.isColor,
|
||||||
|
transform: (multiColor) {
|
||||||
|
if (multiColor!.isGradient) {
|
||||||
|
return GradientBoxBorder(
|
||||||
|
gradient: LinearGradientHelper.fromMultiColor(multiColor),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Border.all(
|
||||||
|
color: multiColor.color,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
defaultValue: null,
|
||||||
|
),
|
||||||
boxShadow: _shadow(context),
|
boxShadow: _shadow(context),
|
||||||
),
|
),
|
||||||
child: (minSize != null && maxSize != null)
|
child: (minSize != null && maxSize != null)
|
||||||
|
@ -14,7 +14,15 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with super program. If not, see <https://www.gnu.org/licenses/>.
|
// along with super program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/// A helper class for getting theme elements.
|
||||||
abstract class ThemeHelper {
|
abstract class ThemeHelper {
|
||||||
|
|
||||||
|
/// Gets a theme element from a list of styles.
|
||||||
|
/// Styles are checked in order, and the first one that passes the
|
||||||
|
/// [valueValidator] is returned.
|
||||||
|
/// If no style passes the [valueValidator], the [defaultValue] is returned.
|
||||||
|
/// If [styles] is null or empty, the [defaultValue] is returned.
|
||||||
|
/// Style elements are transformed using the [transform] function.
|
||||||
static T? getThemeElement<P, T>(
|
static T? getThemeElement<P, T>(
|
||||||
List<P?>? styles, {
|
List<P?>? styles, {
|
||||||
required T? Function(P?)? transform,
|
required T? Function(P?)? transform,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user