Skip to content

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Nov 22, 2025

Close #5880

This PR introduces new services with examples:

  • Accelerometer
  • Barometer
  • Battery
  • Connectivity
  • Gyroscope
  • Magnetometer
  • ScreenBrightness
  • Share
  • UserAccelerometer
  • Wakelock

Introduced support for device sensors including accelerometer, user accelerometer, gyroscope, magnetometer, and barometer. Added corresponding Dart services, Python control classes, event types, and documentation. Updated mkdocs navigation and provided example usage for each sensor.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 22, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: b019017
Status: ✅  Deploy successful!
Preview URL: https://8cae854e.flet-docs.pages.dev
Branch Preview URL: https://sensors.flet-docs.pages.dev

View logs

Added import for numbers utility in sensors.dart and improved code formatting for error handling and debug print statements.
Changed the version exclusion regex and added cleanup commands for multiple flet modules to the clean-pypi.sh script to ensure all related packages are properly cleaned from PyPI.
Bump sensors_plus dependency from 6.1.1 to 7.0.0 in pubspec.yaml and update pubspec.lock accordingly for compatibility with the latest package features and fixes.
Introduces a services property to BasePage and View, allowing management of Service controls via property accessors. The services attribute is now stored in View and proxied through BasePage, improving encapsulation and flexibility.
Sensor example scripts now use `page.services` and `page.controls` instead of session store and `page.add`. Documentation for sensor services was updated for clarity, platform support, and iOS requirements, including details on `NSMotionUsageDescription` for barometer usage.
Corrected docstring references and improved clarity in several control modules. Updated links to use correct attribute names and fixed formatting in flet_map/types.py, cupertino_switch.py, snack_bar.py, and types.py.
Introduces ScreenBrightnessService in Dart and ScreenBrightness control in Python, enabling control and observation of system and application screen brightness. Updates plugin registrants for macOS and Windows, adds documentation and example usage, and includes the screen_brightness dependency in pubspec.yaml.
Fixed example path in ScreenBrightness docs, added documentation for ScreenBrightnessChangeEvent, and updated mkdocs navigation. Clarified that accelerometer, gyroscope, and user accelerometer services are only supported on Android and iOS (not web). Expanded ScreenBrightness docstring with platform notes and Android permission instructions.
Introduced a new Wakelock service to prevent device sleep in both the Flutter and Python Flet SDKs. Added the wakelock_plus dependency to the Flutter project, implemented the WakelockService in Dart, and exposed the Wakelock control in Python with documentation and an example. Updated documentation and navigation to include the new control.
Bump package_info_plus to version 9.0.0 in client with an override, and update wakelock_plus to 1.4.0 in both client and flet package. This ensures compatibility with the latest versions and resolves potential dependency conflicts.
Downgraded wakelock_plus to v1.2.8 in packages/flet and added wakelock_plus v1.4.0 and package_info_plus v9.0.0 to client dependencies. This ensures compatibility and provides additional functionality in the client package.
Introduces Battery service integration in Flet, including Dart and Python implementations, documentation, and example usage. Updates plugin registrants for macOS and Windows, adds battery_plus dependency, and exposes Battery-related types and events in the Python SDK.
Introduced Connectivity service in both Dart and Python SDKs, enabling connectivity status checks and change notifications. Registered connectivity_plus plugin for macOS and Windows clients, updated dependencies, and added example usage and documentation for the new service.
@FeodorFitsner FeodorFitsner changed the title Add sensor services and events to Flet New services: Accelerometer, Barometer, Battery, Connectivity, Gyroscope, Magnetometer, ScreenBrightness, UserAccelerometer, Wakelock Dec 4, 2025
@FeodorFitsner FeodorFitsner changed the title New services: Accelerometer, Barometer, Battery, Connectivity, Gyroscope, Magnetometer, ScreenBrightness, UserAccelerometer, Wakelock New services: Accelerometer, Barometer, Battery, Connectivity, Gyroscope, Magnetometer, ScreenBrightness, UserAccelerometer, Wakelock Dec 4, 2025
Added and enhanced docstrings for classes and methods in battery, browser_context_menu, clipboard, connectivity, service, shared_preferences, storage_paths, and url_launcher modules to improve code documentation and clarity for developers.
Introduces ShareService in Dart and integrates share_plus for sharing text, links, and files. Adds Python API (Share, ShareFile, ShareResult, etc.), documentation, and example usage. Updates plugin registration and dependencies for macOS and Windows.
Replaces the CupertinoActivityType enum with ShareCupertinoActivityType throughout the codebase for clarity and consistency. Updates documentation, mkdocs navigation, and references in __init__.py and share.py. Adds docstrings and improves type annotations for share-related classes and methods.
@FeodorFitsner FeodorFitsner changed the title New services: Accelerometer, Barometer, Battery, Connectivity, Gyroscope, Magnetometer, ScreenBrightness, UserAccelerometer, Wakelock New services: Accelerometer, Barometer, Battery, Connectivity, Gyroscope, Magnetometer, Share, ScreenBrightness, UserAccelerometer, Wakelock Dec 4, 2025
Service-related documentation files were moved from 'controls' and 'types' to a new 'services' directory. The mkdocs navigation was updated to reflect this change, grouping all service docs under a new 'Services' section. Macros and overview rendering were refactored to support both controls and services navigation. Minor cleanup in page.dart and macro Python files.
Introduces new API Reference and Types index documentation pages. Updates mkdocs.yml to include these sections in the navigation, providing better structure and discoverability for API and type documentation. Minor wording improvements in the cookbook index.
Introduced a new `cookbook_overview` macro for generating a dynamic overview list in the cookbook docs. Refactored and generalized the navigation rendering logic in `controls_overview.py` to support arbitrary nav paths, base directories, and skip paths, enabling reuse for different documentation sections. Updated the cookbook index to use the new macro and improved the API reference and cookbook index content.
Renamed Python example files and related media from sdk/python/examples/controls to sdk/python/examples/services for consistency. Updated references in documentation and README files to point to the new services paths. Adjusted code comments and doc macros to reflect the new structure.
Added basic usage examples for BrowserContextMenu, Clipboard, SharedPreferences, and StoragePaths services in the examples directory. Updated corresponding documentation files to include example code and improved structure for better clarity.
Added support for multiple launch modes, in-app web view and browser view configurations, and popup window opening in UrlLauncher for both Dart and Python SDKs. Updated documentation and examples to reflect new features and usage. Exposed BrowserConfiguration, LaunchMode, and WebViewConfiguration in Python package exports and docs.
Consolidated service registries in the Page control by removing separate _user_services and _page_services in favor of a single _services property. Updated related Dart and Python code, including tests and service registration logic, to reflect this change. Deprecated direct service properties on Page in favor of using service classes directly.
Changed a commented dictionary key in test_object_diff_in_place.py from '_user_services' to '_services' for consistency with the underlying code or data structure.
Upgraded battery_plus to 7.0.0, connectivity_plus to 7.0.0, device_info_plus to 12.3.0, and screen_brightness to 2.1.7 in packages/flet/pubspec.yaml. This ensures compatibility with the latest features and bug fixes from these packages.
Introduces a new function to share files from a file path, including UI updates to provide separate buttons for sharing files from bytes and from paths. File sharing from paths is disabled on the web platform.
@FeodorFitsner FeodorFitsner marked this pull request as ready for review December 6, 2025 03:54
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @FeodorFitsner, your pull request is larger than the review limit of 150000 diff characters

Copy link
Contributor

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 introduces 10 new device and platform services to the Flet SDK, significantly expanding hardware sensor and system capability access. The changes include a comprehensive refactoring of the service registry architecture (renaming _user_services and _page_services to a unified _services) and modernization of the UrlLauncher API.

Key changes:

  • New sensor services: Accelerometer, Barometer, Gyroscope, Magnetometer, UserAccelerometer
  • New system services: Battery, Connectivity, ScreenBrightness, Share, Wakelock
  • Service registry consolidation from separate user/page registries to unified _services
  • UrlLauncher API modernization with new launch modes and configuration classes
  • Comprehensive documentation reorganization with new "Services" section

Reviewed changes

Copilot reviewed 121 out of 129 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
SDK Python services Added 10 new service classes with event handlers and async methods
SDK Python page.py Consolidated service registries, deprecated old service properties and methods
SDK Python init.py Exported new services, events, and configuration types
Documentation structure Reorganized with dedicated services section, updated mkdocs navigation
Example files Provided working examples for all new services
Flutter services Implemented Dart counterparts for all new services with proper platform integrations
Dependencies Added battery_plus, connectivity_plus, screen_brightness, share_plus, wakelock_plus

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"BoxShape",
"Brightness",
"BrowserConfiguration",
"BrowserConfiguration",
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Duplicate __all__ entry: "BrowserConfiguration" appears twice (lines 645 and 646). Remove the duplicate.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,2 @@
{{ class_all_options("flet.ShareFile", separate_signature=False) }}
{{ class_all_options("flet.ShareFile", separate_signature=False) }}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Duplicate line: the same template macro is called twice. Remove one of the duplicate lines.

Copilot uses AI. Check for mistakes.
"""
_services: list[Service] = field(default_factory=list)
_user_services: ServiceRegistry = field(default_factory=lambda: ServiceRegistry())
_services: ServiceRegistry = field(default_factory=lambda: ServiceRegistry())
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

This 'lambda' is just a simple wrapper around a callable object. Use that object directly.

Copilot uses AI. Check for mistakes.
from flet.controls.control_event import Event, EventControlType

if TYPE_CHECKING:
from flet.controls.services.accelerometer import Accelerometer # noqa: F401
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Import of 'Accelerometer' is not used.

Copilot uses AI. Check for mistakes.

if TYPE_CHECKING:
from flet.controls.services.accelerometer import Accelerometer # noqa: F401
from flet.controls.services.barometer import Barometer # noqa: F401
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Import of 'Barometer' is not used.

Copilot uses AI. Check for mistakes.
if TYPE_CHECKING:
from flet.controls.services.accelerometer import Accelerometer # noqa: F401
from flet.controls.services.barometer import Barometer # noqa: F401
from flet.controls.services.gyroscope import Gyroscope # noqa: F401
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Import of 'Gyroscope' is not used.

Copilot uses AI. Check for mistakes.
from flet.controls.services.accelerometer import Accelerometer # noqa: F401
from flet.controls.services.barometer import Barometer # noqa: F401
from flet.controls.services.gyroscope import Gyroscope # noqa: F401
from flet.controls.services.magnetometer import Magnetometer # noqa: F401
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Import of 'Magnetometer' is not used.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +15
from flet.controls.services.user_accelerometer import (
UserAccelerometer, # noqa: F401
)
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Import of 'UserAccelerometer' is not used.

Copilot uses AI. Check for mistakes.
)
]

page.controls = [intro, reading]
Copy link
Contributor

Choose a reason for hiding this comment

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

no page.update() required? (or page.add())

nit; intro doesn't need to be stored a variable.

Comment on lines 1 to 6
import logging

import flet_audio_recorder as far

import flet as ft
import flet_audio_recorder as far

logging.basicConfig(level=logging.DEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

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

logging can be removed.

self._i = 1
self.__session = weakref.ref(sess)

# page services
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

Comment on lines +15 to +21
page.services = [
ft.Barometer(
on_reading=handle_reading,
on_error=handle_error,
interval=ft.Duration(milliseconds=500),
),
]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit;
will suggest page.services.append()

Provides device connectivity status and change notifications.
"""

on_connectivity_change: Optional[EventHandler[ConnectivityChangeEvent]] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to on_change?

Comment on lines +12 to +15
class ConnectivityResult(Enum):
"""
Connectivity states.
"""
Copy link
Contributor

@ndonkoHenri ndonkoHenri Dec 6, 2025

Choose a reason for hiding this comment

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

rename to ConnectivityType? result doesnt make much sense to me.

Comment on lines +16 to +24
class Gyroscope(Service):
"""
Streams gyroscope [readings][flet.GyroscopeReadingEvent],
reporting device rotation rate around each axis in `rad/s`.
Note:
* Supported platforms: Android, iOS.
* Web ignores requested sampling intervals.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

add a platform checker and raise exception accordingly.

Comment on lines +17 to +24
__all__ = [
"AccelerometerReadingEvent",
"BarometerReadingEvent",
"GyroscopeReadingEvent",
"MagnetometerReadingEvent",
"SensorErrorEvent",
"UserAccelerometerReadingEvent",
]
Copy link
Contributor

Choose a reason for hiding this comment

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

why have specific events made for specific controls, live in a shared file?
for ex: MagnetometerReadingEvent can be moved to magnetometer.py file, etc.

"x": event.x,
"y": event.y,
"z": event.z,
"timestamp": event.timestamp.microsecondsSinceEpoch,
Copy link
Contributor

Choose a reason for hiding this comment

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

event.timestamp can be sent as datetime instead of microseconds.

Called when connectivity changes.
"""

async def check_connectivity(self) -> list[ConnectivityResult]:
Copy link
Contributor

Choose a reason for hiding this comment

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

get_ will be better than check_, since we dont expect a boolean value ot be returned.
ex: get_connections

/// admonition | Running on iOS
type: danger
On iOS you must also include a key called `NSMotionUsageDescription`
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this in the flet-client too?

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.

feature: A flet "share_plus" service

3 participants