Skip to content

Commit

Permalink
Fix container blend mode
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Aug 9, 2022
1 parent 964924d commit c7f337b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
11 changes: 9 additions & 2 deletions client/lib/controls/container.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:flet_view/utils/animations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
Expand Down Expand Up @@ -86,11 +87,17 @@ class ContainerControl extends StatelessWidget {
opacity: imageOpacity);
}

var gradient = parseGradient(Theme.of(context), control, "gradient");
var blendMode = BlendMode.values.firstWhereOrNull((e) =>
e.name.toLowerCase() ==
control.attrString("blendMode", "")!.toLowerCase());

var boxDecor = BoxDecoration(
color: bgColor,
gradient: parseGradient(Theme.of(context), control, "gradient"),
gradient: gradient,
image: image,
backgroundBlendMode: BlendMode.modulate,
backgroundBlendMode:
bgColor != null || gradient != null ? blendMode : null,
border: parseBorder(Theme.of(context), control, "border"),
borderRadius: parseBorderRadius(control, "borderRadius"));

Expand Down
14 changes: 13 additions & 1 deletion sdk/python/flet/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flet.alignment import Alignment
from flet.border import Border
from flet.constrained_control import ConstrainedControl
from flet.control import Control, OptionalNumber
from flet.control import BlendMode, Control, OptionalNumber
from flet.gradients import Gradient
from flet.image import ImageFit, ImageRepeat
from flet.ref import Ref
Expand Down Expand Up @@ -59,6 +59,7 @@ def __init__(
alignment: Alignment = None,
bgcolor: str = None,
gradient: Gradient = None,
blend_mode: BlendMode = None,
border: Border = None,
border_radius: BorderRadiusValue = None,
image_src: str = None,
Expand Down Expand Up @@ -104,6 +105,7 @@ def __init__(
self.alignment = alignment
self.bgcolor = bgcolor
self.gradient = gradient
self.blend_mode = blend_mode
self.border = border
self.border_radius = border_radius
self.image_src = image_src
Expand Down Expand Up @@ -186,6 +188,16 @@ def gradient(self):
def gradient(self, value: Optional[Gradient]):
self.__gradient = value

# blend_mode
@property
def blend_mode(self):
return self._get_attr("blendMode")

@blend_mode.setter
@beartype
def blend_mode(self, value: Optional[BlendMode]):
self._set_attr("blendMode", value)

# border
@property
def border(self):
Expand Down
33 changes: 33 additions & 0 deletions sdk/python/flet/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@

ScrollMode = Literal[None, True, False, "none", "auto", "adaptive", "always", "hidden"]

BlendMode = Literal[
"clear",
"color",
"colorBurn",
"colorDodge",
"darken",
"difference",
"dst",
"dstATop",
"dstIn",
"dstOut",
"dstOver",
"exclusion",
"hardLight",
"hue",
"lighten",
"luminosity",
"modulate",
"multiply",
"overlay",
"plus",
"saturation",
"screen",
"softLight",
"src",
"srcATop",
"srcIn",
"srcOut",
"srcOver",
"values",
"xor",
]


class Control:
def __init__(
Expand Down
40 changes: 1 addition & 39 deletions sdk/python/flet/shader_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from beartype import beartype

from flet.constrained_control import ConstrainedControl
from flet.control import Control, OptionalNumber
from flet.control import BlendMode, Control, OptionalNumber
from flet.gradients import Gradient
from flet.ref import Ref
from flet.types import (
Expand All @@ -14,44 +14,6 @@
ScaleValue,
)

try:
from typing import Literal
except:
from typing_extensions import Literal

BlendMode = Literal[
"clear",
"color",
"colorBurn",
"colorDodge",
"darken",
"difference",
"dst",
"dstATop",
"dstIn",
"dstOut",
"dstOver",
"exclusion",
"hardLight",
"hue",
"lighten",
"luminosity",
"modulate",
"multiply",
"overlay",
"plus",
"saturation",
"screen",
"softLight",
"src",
"srcATop",
"srcIn",
"srcOut",
"srcOver",
"values",
"xor",
]


class ShaderMask(ConstrainedControl):
def __init__(
Expand Down

0 comments on commit c7f337b

Please sign in to comment.