Skip to main content

View

View is the top most container for all other controls.

A root view is automatically created when a new user session started. From layout perspective the View represents a Column control, so it has a similar behavior and shares same properties.

Properties

appbar

A AppBar control to display at the top of the Page.

auto_scroll

True if scrollbar should automatically move its position to the end when children updated. Must be False for scroll_to() to work.

bgcolor

Background color of the view.

can_pop

This property controls whether the view can be uncoditionally removed from navigation either programmatically, say by modifying page.views list, or when a user uses device back button.

By default, can_pop is True which means the view will be removed with no questions asked. However, if you set View.can_pop to False then you can add View.on_confirm_pop event handler where you can open an alert dialog to confirm or do other checks and then call View.confirm_pop(True|False) method to either allow or prevent view from removal.

Another use case is setting page.views[0].canPop = False for root view to prevent closing the app with hardware back button on Android.

controls

A list of Controls to display on the Page.

For example, to add a new control to a page:

page.controls.append(ft.Text("Hello!"))
page.update()

or to get the same result as above using page.add() shortcut method:

page.add(ft.Text("Hello!"))

To remove the top most control on the page:

page.controls.pop()
page.update()

Value is of a list of Controls.

decoration

The background decoration.

Value is of type BoxDecoration.

drawer

A NavigationDrawer control to display as a panel sliding from the start edge of the view.

end_drawer

A NavigationDrawer control to display as a panel sliding from the end edge of the view.

floating_action_button

A FloatingActionButton control to display on top of Page content.

floating_action_button_location

Describes position of floating_action_button

Value is of type FloatingActionButtonLocation

foreground_decoration

The foreground decoration.

Value is of type BoxDecoration.

fullscreen_dialog

Whether this view is a full-screen dialog.

In Material and Cupertino, being fullscreen has the effects of making the app bars have a close button instead of a back button. On iOS, dialogs transitions animate differently and are also not closeable with the back swipe gesture.

Value is of type bool and defaults to False.

horizontal_alignment

How the child Controls should be placed horizontally.

Value is of type CrossAxisAlignment and defaults to CrossAxisAlignment.START.

on_scroll_interval

Throttling in milliseconds for on_scroll event.

Value is of type int and defaults to 10.

padding

A space between page contents and its edges.

Value is of type PaddingValue and defaults to padding.all(10).

route

View's route - not currently used by Flet framework, but can be used in a user program to update page.route when a view popped.

Value is of type str

scroll

Enables a vertical scrolling for the Page to prevent its content overflow.

Value is of type ScrollMode.

spacing

Vertical spacing between controls on the Page. Default value is 10 virtual pixels. Spacing is applied only when vertical_alignment is set to MainAxisAlignment.START, MainAxisAlignment.END or MainAxisAlignment.CENTER.

Value is of type [OptionalNumber] and defaults to 10

vertical_alignment

How the child Controls should be placed vertically.

Value is of type MainAxisAlignment and defaults to MainAxisAlignment.START.

Methods

confirm_pop(allow: bool)

Either allow or cancel view removal from the navigation. Used together with View.can_pop property and View.on_confirm_pop event.

scroll_to(offset, delta, key, duration, curve)

Moves scroll position to either absolute offset, relative delta or jump to the control with specified key.

See Column.scroll_to() for method details and examples.

Events

on_confirm_pop

Fires when a view is about to be removed from the navigation. Allows to ask user for confirmation or do other checks and either allow or cancel removal of a view by calling View.confirm_pop(True | False) method. This event is fired if View.can_pop set to False.

on_scroll

Fires when scroll position is changed by a user.

Event handler argument is of type OnScrollEvent.

OSZAR »