Repository: flet-dev/flet
Issue category: Bug Report

Issue:
Regression in `Markdown.code_theme` when using `MarkdownCodeTheme` enum
A custom theme works great although the only issue I faced was setting `code_theme` with `ft.MarkdownCodeTheme.ATOM_ONE_DARK` or any other value but **only** using `ft.MarkdownTheme` class the error it throws is: 

# Code
```python
import flet as ft

data = """
```python
class MyClass(object):
    def __init__(self):
        pass
        
    def greet(self):
        print("Hello World")
    ```
"""
def main(page: ft.Page):
    page.add(
        ft.Markdown(
            value=data,
            code_theme=ft.MarkdownCodeTheme.ATOM_ONE_DARK,
            extension_set=ft.MarkdownExtensionSet.GITHUB_WEB,
        )
    )
ft.app(main)
```
<details>
  <summary>Error</summary>

  ```bash
  (.venv) PS D:\CodingFolder\myCodingFilesPy\Flet\leraning> flet run .\theme\ --web                                                                                                                        
  http://127.0.0.1:54949
  D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\websockets\legacy\server.py:1185: DeprecationWarning: remove second argument of ws_handler
    warnings.warn("remove second argument of ws_handler", DeprecationWarning)
  Unhandled error processing page session 49apGh5JlJ9Wkk0V: Traceback (most recent call last):
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet_web\fastapi\flet_app.py", line 141, in __on_session_created
      await asyncio.get_running_loop().run_in_executor(
    File "C:\ProgramData\anaconda3\Lib\concurrent\futures\thread.py", line 58, in run
      result = self.fn(*self.args, **self.kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\theme\main.py", line 12, in main
      page.add(
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\page.py", line 737, in add
      r = self.__update(self)
          ^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\page.py", line 835, in __update
      commands, added_controls, removed_controls = self.__prepare_update(*controls)
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\page.py", line 851, in __prepare_update
      control.build_update_commands(
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\control.py", line 497, in build_update_commands
      innerCmds = ctrl._build_add_commands(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\control.py", line 562, in _build_add_commands
      childCmd = control._build_add_commands(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\control.py", line 551, in _build_add_commands
      command = self._build_command(False)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\control.py", line 578, in _build_command
      self.before_update()
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\markdown.py", line 403, in before_update
      self._set_attr_json("codeTheme", self.__code_theme)
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\control.py", line 189, in _set_attr_json
      nv = self._convert_attr_json(
           ^^^^^^^^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\control.py", line 197, in _convert_attr_json
      json.dumps(value, cls=EmbedJsonEncoder, separators=(",", ":"))
    File "C:\ProgramData\anaconda3\Lib\json\__init__.py", line 238, in dumps
      **kw).encode(obj)
            ^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\embed_json_encoder.py", line 59, in encode
      return super().encode(self._convert_enums(o))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\ProgramData\anaconda3\Lib\json\encoder.py", line 200, in encode
      chunks = self.iterencode(o, _one_shot=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\ProgramData\anaconda3\Lib\json\encoder.py", line 258, in iterencode
      return _iterencode(o, 0)
             ^^^^^^^^^^^^^^^^^
    File "D:\CodingFolder\myCodingFilesPy\Flet\leraning\.venv\Lib\site-packages\flet\core\embed_json_encoder.py", line 49, in default
      obj_as_dict = self._convert_enums(obj.__dict__)
                                        ^^^^^^^^^^^^
  AttributeError: 'mappingproxy' object has no attribute '__dict__'
  ```
</details>

 ![image](https://github.com/user-attachments/assets/79ad892b-aa1b-4e68-9570-108835a23f54)


### I think there's something wrong with `ft.MarkdownTheme` class because when I used `"atom-one-dark"` it worked. When I run the same code but with `flet` version, `0.24.1` it worked as expected. Kindly raise issue regarding this.

_Originally posted by @tanmay-bhatgare in https://github.com/flet-dev/flet/issues/4342#issuecomment-2476781933_
            


Hints:

Patch:
diff --git a/sdk/python/packages/flet/src/flet/core/markdown.py b/sdk/python/packages/flet/src/flet/core/markdown.py
index 118e4e1c4..77a761c88 100644
--- a/sdk/python/packages/flet/src/flet/core/markdown.py
+++ b/sdk/python/packages/flet/src/flet/core/markdown.py
@@ -400,7 +400,12 @@ def before_update(self):
         self._set_attr_json("codeStyle", self.__code_style)
         self._set_attr_json("codeStyleSheet", self.__code_style_sheet)
         self._set_attr_json("mdStyleSheet", self.__md_style_sheet)
-        self._set_attr_json("codeTheme", self.__code_theme)
+        self._set_attr_json(
+            "codeTheme",
+            self.__code_theme.value
+            if isinstance(self.__code_theme, MarkdownCodeTheme)
+            else self.__code_theme,
+        )
 
     def _get_children(self):
         if self.__img_error_content is not None:
@@ -483,11 +488,13 @@ def md_style_sheet(self, value: Optional[MarkdownStyleSheet]):
 
     # code_theme
     @property
-    def code_theme(self) -> Optional[MarkdownCodeTheme]:
+    def code_theme(self) -> Optional[Union[MarkdownCodeTheme, MarkdownCustomCodeTheme]]:
         return self.__code_theme
 
     @code_theme.setter
-    def code_theme(self, value: Optional[MarkdownCodeTheme]):
+    def code_theme(
+        self, value: Optional[Union[MarkdownCodeTheme, MarkdownCustomCodeTheme]]
+    ):
         self.__code_theme = value
 
     # code_style


Test patch: