Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.5

### Bug fixes

* Fix `flet run --web` and other Flet web apps failing to start with FastAPI 0.145 or later, which removed the `openapi_prefix` argument ([#6984](https://github.com/flet-dev/flet/issues/6984), [#6988](https://github.com/flet-dev/flet/pull/6988)) by @FeodorFitsner.

## 1.0.4

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ packages:
path: "../packages/flet"
relative: true
source: path
version: "1.0.4"
version: "1.0.5"
flet_ads:
dependency: "direct main"
description:
Expand Down
4 changes: 4 additions & 0 deletions packages/flet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.5

_No changes in the `flet` Dart package; version bumped for release coordination with the fix for Flet web apps failing to start with FastAPI 0.145 or later ([#6984](https://github.com/flet-dev/flet/issues/6984), [#6988](https://github.com/flet-dev/flet/pull/6988))._

## 1.0.4

* Depend on `screen_brightness_platform_interface`, `screen_brightness_android` and `screen_brightness_ios` instead of `screen_brightness`, and drive `ScreenBrightnessService` through `ScreenBrightnessPlatform.instance`: apps embedding `flet` no longer register the Windows, macOS and OHOS `screen_brightness` plugins, whose Windows one talks to monitors over DDC/CI while the app runs ([#6629](https://github.com/flet-dev/flet/issues/6629), [#6493](https://github.com/flet-dev/flet/issues/6493), [#6925](https://github.com/flet-dev/flet/pull/6925)) by @ndonkoHenri.
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flet
description: Write entire Flutter app in Python or add server-driven UI experience into existing Flutter app.
homepage: https://flet.dev
repository: https://github.com/flet-dev/flet/tree/main/packages/flet
version: 1.0.4
version: 1.0.5

# Supported platforms
platforms:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import flet_web.fastapi

_DEFAULT_RESPONSE_CLASS = Default(JSONResponse)


class FastAPI(fastapi.FastAPI):
"""
Expand All @@ -38,7 +40,7 @@ def __init__(
openapi_tags: Optional[list[dict[str, Any]]] = None,
servers: Optional[list[dict[str, Union[str, Any]]]] = None,
dependencies: Optional[Sequence[Depends]] = None,
default_response_class: type[Response] = Default(JSONResponse),
default_response_class: type[Response] = _DEFAULT_RESPONSE_CLASS,
redirect_slashes: bool = True,
docs_url: Optional[str] = "/docs",
redoc_url: Optional[str] = "/redoc",
Expand Down Expand Up @@ -139,8 +141,7 @@ async def lifespan(app: fastapi.FastAPI):
terms_of_service=terms_of_service,
contact=contact,
license_info=license_info,
openapi_prefix=openapi_prefix,
root_path=root_path,
root_path=root_path or openapi_prefix,
root_path_in_servers=root_path_in_servers,
responses=responses,
callbacks=callbacks,
Expand Down
35 changes: 35 additions & 0 deletions sdk/python/packages/flet-web/tests/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
from fastapi.testclient import TestClient

from flet_web.fastapi import FastAPI


@pytest.mark.parametrize(
("kwargs", "expected_root_path"),
[
({}, ""),
({"root_path": "/app"}, "/app"),
({"openapi_prefix": "/legacy"}, "/legacy"),
({"openapi_prefix": "/legacy", "root_path": "/app"}, "/app"),
],
)
def test_fastapi_root_path_and_lifecycle(kwargs, expected_root_path):
"""`root_path` falls back to `openapi_prefix`, and lifecycle hooks run once."""
events = []
app = FastAPI(
**kwargs,
on_startup=[lambda: events.append("startup")],
on_shutdown=[lambda: events.append("shutdown")],
)

@app.get("/path")
def get_root_path():
return {"root_path": app.root_path}

with TestClient(app) as client:
assert events == ["startup"]
response = client.get("/path")
assert response.status_code == 200
assert response.json() == {"root_path": expected_root_path}

assert events == ["startup", "shutdown"]
Loading