-
Notifications
You must be signed in to change notification settings - Fork 536
View.can_pop
and View.on_confirm_pop
#5284
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
Conversation
Hi @FeodorFitsner , I updated some code to 0.28.3 this morning and this navigation changes and everything in general worked very nice. I have a suggestion for a feature associated with the pop of the views. In android flet 0.27.6, on_view_pop was called directly when native android button pressed, making possible a view exit logic, like a confirmation back, save or exit dialog. Now back button event pop the view first and then on_view_pop is called wich (I can be wrong) leaves no options to any logics. It could be possible to associate can_pop with other event called on_pop, for example, that gives the opportunity to page.views.pop() yourself or do other things instead? Thank you for everything. |
Got it. In 0.28.3 we added a few hooks to |
I undertand, It seems I was wrong with interpretation of the new pop mechanics. I tryed the method you mention when defining the View 's:
But the can_pop = False disable the pop event so on_confirm_pop never is called and function(args) never executed. The hardware back button dont do nothing. This has sense for you? Thanks. |
Make sure you have I'm using this example to test with 0.28.3 and I can see "on_confirm_pop" printed when clicking "Back" on "Store" screen: import flet as ft
def main(page: ft.Page):
page.title = "Routes Example"
def route_change(e):
page.views.clear()
def confirm_route_pop(e):
print("on_confirm_pop")
e.control.confirm_pop(True)
page.views.append(
ft.View(
"/",
[
ft.AppBar(title=ft.Text("Flet app"), bgcolor=ft.Colors.YELLOW),
ft.Button("Visit Store", on_click=lambda _: page.go("/store")),
],
can_pop=False,
on_confirm_pop=confirm_route_pop,
)
)
if page.route == "/store":
page.views.append(
ft.View(
"/store",
[
ft.AppBar(title=ft.Text("Store"), bgcolor=ft.Colors.YELLOW),
ft.Button("Go Home", on_click=lambda _: page.go("/")),
],
can_pop=False,
on_confirm_pop=confirm_route_pop,
)
)
page.update()
def view_pop(e):
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
page.on_route_change = route_change
page.on_view_pop = view_pop
page.go(page.route)
ft.app(main) |
Absolutely, it works perfectly on desktop. But when I do the next secuence of things:
Then the button does nothing because the property can_pop = False is disabling the pop event, not on_confirm_pop or page.on_view_pop event is generated. If can_pop=True pressing android sistem button generates pop event that pops a view directly, without the oportunity to have logic between. In the 2 cases android back sistem button give no oportunity to display pop logic. Thats only on android once apk done. Thanks Feodor. |
OK, I just bumped Flet version in Flet build template. Delete "build" folder of your app and rebuild. |
I tryed again with the new build template and Flet dont catch any event associated with sistem back button on mobile device when can_pop=False. So page.on_view_pop and on_confirm_pop are never being called. I think could be a personal code issue, but it seems imposible to me to reach a combination that makes any sistem back button associated event handler being fired when can_pop = False when testing in device. |
Im going to try some hipersimplistic variants so I can give you more feed back about it. Thanks. |
What version of Flet do you have inside of your APK? It's in |
Fonunded in version.py inside libpythonsitepackages.so: """Provide the current Flet version.""" import os import flet will be replaced by CI ... |
Can you do a simple code repro for me please? |
Sure!
When I build this apk with the same toml and everything, it gives the same result as my real code, pushing sistem back button not firing on_confirm_pop. |
Hi Feodor, was posible for you to reproduce it? Its the simplest example I can do. I'm in no hurry, it's just in case you needed more information. |
Looking into that. |
commit 2a1facb Author: Henning Wilmer <57907680+HenningCode@users.noreply.github.com> Date: Thu Jun 12 18:37:58 2025 +0200 Change the type alias from a class to a real rename (#5258) commit 8f83b45 Author: PythonPan <2292551082@qq.com> Date: Fri Jun 13 00:29:49 2025 +0800 Fix page.run_thread does not receive kwargs (#5318) (#5320) commit bf09a2c Author: Antón Fernández Pérez <134967595+SIRGPrice@users.noreply.github.com> Date: Wed Jun 11 21:16:41 2025 +0200 Update remove_control_payload.dart (#5353) Android apk app randomly generates this error in logcat: E [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: type 'Null' is not a subtype of type 'String' #0 new List.from (dart:core-patch/array_patch.dart:30) #1 new RemoveControlPayload.fromJson (package:flet/src/protocol/remove_control_payload.dart:7) #2 appReducer (package:flet/src/reducers.dart:376) #3 Store._createReduceAndNotify.<anonymous closure> (package:redux/src/store.dart:235) #4 Store.dispatch (package:redux/src/store.dart:267) #5 FletServer._onMessage (package:flet/src/flet_server.dart:265) #6 FletTcpSocketServerProtocol._onMessage (package:flet/src/flet_server_protocol_tcp_socket.dart:125) #7 FletTcpSocketServerProtocol.connect.<anonymous closure> (package:flet/src/flet_server_protocol_tcp_socket.dart:94) #8 _RootZone.runUnaryGuarded (dart:async/zone.dart:1778) #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381) #10 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312) #11 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798) #12 _StreamController._add (dart:async/stream_controller.dart:663) #13 _StreamController.add (dart:async/stream_controller.dart:618) #14 _Socket._onData (dart:io-patch/socket_patch.dart:2904) #15 _RootZone.runUnaryGuarded (dart:async/zone.dart:1778) #16 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381) #17 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312) #18 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798) #19 _StreamController._add (dart:async/stream_controller.dart:663) #20 _StreamController.add (dart:async/stream_controller.dart:618) #21 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:2323) #22 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1646) #23 _microtaskLoop (dart:async/schedule_microtask.dart:40) #24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49) commit 1c040ef Author: Feodor Fitsner <feodor@appveyor.com> Date: Sun May 18 20:13:06 2025 -0400 Preparing Flet v0.28.3 release (#5306) * Fix images displaying in web mode with non-empty page name Fix #5198 * Fix page.on_view_pop event handling Fix #5302 * Fix FilePicker.save_file() for Android and iOS Fix #5301 * PubSub: allow multiple subscribers per session, per topic Close #5303 * Bump version to 0.28.3, updated changelog commit 69e4e10 Author: Feodor Fitsner <feodor@appveyor.com> Date: Sat May 10 13:49:30 2025 -0700 Prepare Flet 0.28.2 (#5295) * Added missing imports into `__init__.py` * Changelog, bumped version to 0.28.2 * fix WindowDragArea * update code in readme * Upated changelog --------- Co-authored-by: ndonkoHenri <robotcoder4@protonmail.com> commit 7ce8e48 Author: Feodor Fitsner <feodor@appveyor.com> Date: Thu May 8 12:38:37 2025 -0700 Update .appveyor.yml commit deb38c7 Author: Feodor Fitsner <feodor@appveyor.com> Date: Thu May 8 09:11:14 2025 -0700 v0.28.0 release notes (#5286) * v0.28.0 release notes * Fix "Fixed:" commit fcc712f Author: Feodor Fitsner <feodor@appveyor.com> Date: Wed May 7 10:29:03 2025 -0700 `View.can_pop` and `View.on_confirm_pop` (#5284) * View.can_pop and View.on_confirm_pop * Dismissible and View: added 5 minutes timeout for confirm callbacks commit c3d550a Author: Owen McDonnell <7119543+OwenMcDonnell@users.noreply.github.com> Date: Sat May 3 16:41:10 2025 -0700 Update CONTRIBUTING.md (#5268) note about activating .zprofile variables. commit f4b83ae Author: bl1nch <130155870+bl1nch@users.noreply.github.com> Date: Tue Apr 29 07:31:08 2025 +0600 UTF-8 encoding for pyproject.toml (#5203) commit e3f4d16 Author: Feodor Fitsner <feodor@appveyor.com> Date: Fri Apr 4 17:17:48 2025 -0700 Update reorderable_list_view.dart commit add9c61 Author: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Sat Apr 5 02:10:23 2025 +0200 feat: custom `ReorderableListView` drag handle listeners (#5051) * initial commit * `ReorderableListView`: mouse_cursor, show_default_drag_handles * generated files * flutter 3.29.0 commit 440009d Author: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Sat Apr 5 02:04:32 2025 +0200 feat: expose events (`on_double_tap`, `on_pan_start`) in `WindowDragArea` (#5043) * improve events typing in gesture_detector.py * window.start_dragging * delete window_drag_area.dart * rework WindowDragArea inheriting from GestureDetector * export more utils
Close #5280
Summary by Sourcery
Add support for customizing view navigation behavior with
can_pop
andon_confirm_pop
propertiesNew Features:
can_pop
property to control whether a view can be poppedon_confirm_pop
event handler to provide custom pop confirmation logicEnhancements: