Skip to content

v1: Web Multi-View - embedding Flet web app into existing web page #5274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 6, 2025

Conversation

FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented May 4, 2025

Summary by Human

before_main

A new before_main arg added to ft.run(). before_main is a hook that allows to reliable configure page-level event handlers before Flutter client starts sending events. before_main is a function that accepts one parameter: page: ft.Page

Example usage:

def config(page: ft.Page):
  page.on_resize = lambda e: print("Page resized!")

def main(page: ft.Page):
  page.add(ft.Text("Hello!"))

ft.run(main, before_main=config)

Summary by Sourcery

Implement Web Multi-View support for embedding Flet web apps into existing web pages

New Features:

  • Add multi-view support for web applications
  • Enable embedding Flet web apps into existing web pages
  • Introduce initial data passing for multi-view scenarios

Enhancements:

  • Refactor page and view control architecture
  • Improve flexibility of web app rendering
  • Add support for dynamic view management

Chores:

  • Remove deprecated methods
  • Clean up unused imports and code
  • Simplify configuration handling

@FeodorFitsner FeodorFitsner requested a review from ndonkoHenri May 4, 2025 00:14
@ndonkoHenri ndonkoHenri requested a review from Copilot May 4, 2025 02:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds multi-view support to allow embedding Flet web apps into existing web pages while improving the application's configuration and initialization flow.

  • Introduces a new multi-view initialization mechanism with initial data passing and view constraints.
  • Refactors configuration handling in both the worker setup and Flutter bootstrap process.
  • Cleans up meta tags and inline configurations in the main HTML file.

Reviewed Changes

Copilot reviewed 28 out of 45 changed files in this pull request and generated 1 comment.

File Description
client/web/python.js Updated worker initialization to use flet configuration values.
client/web/index.html Replaced meta tags with a flet config object and added multi-view initialization.
client/web/flutter_bootstrap.js Refactored configuration merging and Flutter app bootstrap using a new config object.
Files not reviewed (17)
  • client/lib/main.dart: Language not supported
  • packages/flet/lib/flet.dart: Language not supported
  • packages/flet/lib/src/controls/circle_avatar.dart: Language not supported
  • packages/flet/lib/src/controls/markdown.dart: Language not supported
  • packages/flet/lib/src/controls/page.dart: Language not supported
  • packages/flet/lib/src/controls/view.dart: Language not supported
  • packages/flet/lib/src/flet_app.dart: Language not supported
  • packages/flet/lib/src/flet_backend.dart: Language not supported
  • packages/flet/lib/src/models/multi_view.dart: Language not supported
  • packages/flet/lib/src/models/page_args_model.dart: Language not supported
  • packages/flet/lib/src/utils/locale.dart: Language not supported
  • packages/flet/lib/src/utils/platform_utils_non_web.dart: Language not supported
  • packages/flet/lib/src/utils/platform_utils_web.dart: Language not supported
  • packages/flet/lib/src/utils/session_store_web.dart: Language not supported
  • packages/flet/lib/src/widgets/flet_app_context.dart: Language not supported
  • packages/flet/lib/src/widgets/flet_store_mixin.dart: Language not supported
  • packages/flet/lib/src/widgets/page_context.dart: Language not supported
Comments suppressed due to low confidence (1)

client/web/python.js:33

  • Ensure that the 'flet.noCdn' flag is set intentionally and that 'flet.pyodideUrl' is guaranteed to be defined when noCdn is true.
pyodideUrl: flet.noCdn ? flet.pyodideUrl : defaultPyodideUrl,

},
viewConstraints: {
minWidth: 620,
//maxWidth: 320,
Copy link
Preview

Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If the commented-out view constraint is no longer required, consider removing it to improve code clarity; otherwise, add a clarifying comment explaining its purpose.

Suggested change
//maxWidth: 320,

Copilot uses AI. Check for mistakes.

@@ -48,6 +48,7 @@ def main(page: ft.Page):

src: OptionalString = None
src_base64: OptionalString = None
src_bytes: Optional[bytes] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should perhaps think of having just one src prop, and have intelligent ifs on dart end.

Breaking changes: DragTarget.on_will_accept is of `DragWillAcceptEvent` type with `accept: bool` field. Use `e.accept` instead of `e.data`. DragTarget.on_leave is of `DragTargetLeaveEvent` type with `src_id` field. Use `e.src_id` instead of `e.data`.
@FeodorFitsner FeodorFitsner merged commit f95f561 into v1 May 6, 2025
2 checks passed
@FeodorFitsner FeodorFitsner deleted the feodor/v1-multi-view branch May 6, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants