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
import flet as ft
data = """
```python
class MyClass(object):
def __init__(self):
pass
def greet(self):
print("Hello World")
<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__'
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.
A custom theme works great although the only issue I faced was setting
code_theme
withft.MarkdownCodeTheme.ATOM_ONE_DARK
or any other value but only usingft.MarkdownTheme
class the error it throws is:Code
""" 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)
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 withflet
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