37
37
38
38
import random
39
39
from enum import Enum , EnumMeta
40
- from typing import Dict , List , Optional , Union
40
+ from typing import TYPE_CHECKING , Dict , List , Optional , Union
41
41
from warnings import warn
42
42
43
+ if TYPE_CHECKING :
44
+ from flet .core .types import ColorValue
45
+
43
46
from flet .utils import deprecated
44
47
45
48
@@ -56,9 +59,16 @@ def __getattribute__(self, item):
56
59
57
60
58
61
class colors (str , Enum , metaclass = ColorsDeprecated ):
59
- def with_opacity (self , opacity : Union [int , float ]) -> str :
62
+ @staticmethod
63
+ @deprecated (
64
+ reason = "Use Colors.with_opacity() method instead." ,
65
+ version = "0.25.0" ,
66
+ delete_version = "0.28.0" ,
67
+ )
68
+ def with_opacity (opacity : Union [int , float ], color : "ColorValue" ) -> str :
60
69
assert 0 <= opacity <= 1 , "opacity must be between 0 and 1"
61
- return f"{ self .value } ,{ opacity } "
70
+ color_str = color .value if isinstance (color , Enum ) else color
71
+ return f"{ color_str } ,{ opacity } "
62
72
63
73
@staticmethod
64
74
def random ():
@@ -416,21 +426,11 @@ def random_color():
416
426
417
427
418
428
class Colors (str , Enum ):
419
- def with_opacity (self , opacity : Union [int , float ]) -> str :
420
- """
421
- Returns the color with the specified opacity.
422
-
423
- Args:
424
- opacity: The opacity value, which must be between 0 and 1.
425
-
426
- Returns:
427
- A string representing the color value with the specified opacity appended.
428
-
429
- Raises:
430
- AssertionError: If the opacity is not between 0 and 1 (inclusive).
431
- """
429
+ @staticmethod
430
+ def with_opacity (opacity : Union [int , float ], color : "ColorValue" ) -> str :
432
431
assert 0 <= opacity <= 1 , "opacity must be between 0 and 1"
433
- return f"{ self .value } ,{ opacity } "
432
+ color_str = color .value if isinstance (color , Enum ) else color
433
+ return f"{ color_str } ,{ opacity } "
434
434
435
435
@staticmethod
436
436
def random (
0 commit comments