Skip to content

feat: make SharedPreferences support int, float, bool and list[str]#6267

Open
ndonkoHenri wants to merge 8 commits intomainfrom
improve-shared-prefs
Open

feat: make SharedPreferences support int, float, bool and list[str]#6267
ndonkoHenri wants to merge 8 commits intomainfrom
improve-shared-prefs

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Mar 6, 2026

Summary by Sourcery

Extend SharedPreferences to support multiple primitive types and lists while improving platform build configuration handling and documentation.

New Features:

  • Allow SharedPreferences to store and retrieve str, int, float, bool, and list[str] values across Python and Flutter layers.
  • Document how to use subprocess to invoke external system commands from Flet apps, including Android-specific examples.

Bug Fixes:

  • Make CLI boolean parsing for macOS entitlements and Android features/permissions case-insensitive to avoid unexpected failures.
  • Correct documentation references for permissions resolution order and flet run docs paths.
  • Fix ads package changelog by converting the Unreleased section into a tagged 0.82.0 release entry with proper issue and PR links.

Enhancements:

  • Clarify and standardize CLI and TOML value formats for iOS, macOS, and Android build options and entitlements, with richer examples and template translations.
  • Tighten SharedPreferences type validation and add a dedicated type alias for supported value types in the Python API.
  • Improve type hints and navigation in Python docs and auth APIs, including OAuth token typing and cookbook link fixes.
  • Refine Flet CLI build command help text and link to the full publishing guide.
  • Update deep linking and publishing docs with additional platform references and concrete manifest/plist translation examples.
  • Add Subprocess cookbook page to the documentation navigation.
  • Clarify release-preparation skill instructions for changelog handling and author attribution.

Documentation:

  • Expand platform-specific publishing docs (iOS, macOS, Android) with supported value forms, examples, and rendered template snippets.
  • Add detailed deep linking examples for Android and iOS, showing how TOML config maps to platform manifests.
  • Introduce a new cookbook recipe demonstrating safe subprocess usage, including launching Android activities from Flet apps.

Tests:

  • Broaden SharedPreferences integration tests to cover all supported value types and rejection of unsupported types.

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.

We've reviewed this pull request using the Sourcery rules engine

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 expands SharedPreferences to support additional primitive value types end-to-end (Python SDK ↔ Flutter service), while also updating build CLI boolean parsing/help text and making several documentation improvements (publish guides + cookbook).

Changes:

  • Extend SharedPreferences to support int, float, bool, and list[str] (Python typing + Dart service implementation) and broaden integration test coverage.
  • Update flet build CLI boolean parsing to be case-insensitive for several flags and align related publish documentation/examples.
  • Add a new cookbook article (Subprocess) and update MkDocs navigation; apply assorted docs/changelog/lockfile maintenance updates.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
sdk/python/packages/flet/src/flet/controls/services/shared_preferences.py Adds a SharedPreferencesValueType alias, tighter input validation, and improved docstrings.
packages/flet/lib/src/services/shared_preferences.dart Implements multi-type set/get support using the platform shared_preferences API.
sdk/python/packages/flet/integration_tests/controls/services/test_shared_preferences.py Extends CRUD integration test to cover new supported types and invalid inputs.
sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py Makes several CLI boolean parsers case-insensitive and tweaks help text.
sdk/python/packages/flet/src/flet/auth/authorization_service.py Adds an explicit return type to get_token().
sdk/python/packages/flet/docs/publish/android.md Docs updates for resolution order, boolean forms, and “template translation” examples.
sdk/python/packages/flet/docs/publish/ios.md Docs updates for supported forms/examples and template-translation sections.
sdk/python/packages/flet/docs/publish/macos.md Docs updates for supported forms/examples and template-translation sections.
sdk/python/packages/flet/docs/publish/index.md Adds “template translation” details and updates deep-linking references/links.
sdk/python/packages/flet/docs/cookbook/subprocess.md New cookbook recipe covering subprocess usage (non-web).
sdk/python/packages/flet/docs/cookbook/assets.md Updates control link format for Image.
sdk/python/packages/flet/mkdocs.yml Adds the new Subprocess cookbook page to navigation.
sdk/python/packages/flet-cli/src/flet_cli/commands/build.py Adds a publish documentation link in the command docstring.
sdk/python/packages/flet-ads/CHANGELOG.md Changelog entry formatting/version section update.
client/pubspec.lock Updates pinned Dart transitive dependencies.
.codex/skills/prepare-flet-release/SKILL.md Tightens release-prep instructions (author attribution + changelog scan guidance).

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

i = p.find("=")
if i > -1:
macos_entitlements[p[:i]] = p[i + 1 :] == "True"
macos_entitlements[p[:i]] = p[i + 1 :].strip().lower() == "true"
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

--macos-entitlements values are parsed as ... == "true", which silently treats any other value (e.g. foo) as False. This contradicts the CLI/docs wording that only true/false are accepted and can mask user mistakes; consider validating the value and failing with cleanup() when it’s not one of {true,false} (similar to the --info-plist parsing above).

Suggested change
macos_entitlements[p[:i]] = p[i + 1 :].strip().lower() == "true"
k = p[:i]
v = p[i + 1 :].strip()
v_lower = v.lower()
if v_lower in {"true", "false"}:
macos_entitlements[k] = v_lower == "true"
else:
self.cleanup(1, f"Invalid macOS entitlement value: {p}")

Copilot uses AI. Check for mistakes.
i = p.find("=")
if i > -1:
android_permissions[p[:i]] = p[i + 1 :] == "True"
android_permissions[p[:i]] = p[i + 1 :].strip().lower() == "true"
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

--android-permissions parsing treats any value other than case-insensitive true as False. If a user passes an invalid token (typo), it will be accepted and flipped to False; please validate values and error out unless the value is true/false.

Suggested change
android_permissions[p[:i]] = p[i + 1 :].strip().lower() == "true"
key = p[:i]
value_str = p[i + 1 :].strip()
value_lc = value_str.lower()
if value_lc in {"true", "false"}:
android_permissions[key] = value_lc == "true"
else:
self.cleanup(
1,
f"Invalid Android permission value for {key}: {value_str}",
)

Copilot uses AI. Check for mistakes.
i = p.find("=")
if i > -1:
android_features[p[:i]] = p[i + 1 :] == "True"
android_features[p[:i]] = p[i + 1 :].strip().lower() == "true"
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

--android-features parsing currently accepts arbitrary values and maps them to False unless they equal true (case-insensitive). To avoid surprising behavior and to match the documented true|false contract, validate the value and fail fast when it’s not true or false.

Suggested change
android_features[p[:i]] = p[i + 1 :].strip().lower() == "true"
value_str = p[i + 1 :].strip()
value_normalized = value_str.lower()
if value_normalized not in ("true", "false"):
self.cleanup(
1,
f"Invalid Android feature value for '{p[:i]}': '{value_str}'. Expected 'true' or 'false'.",
)
android_features[p[:i]] = value_normalized == "true"

Copilot uses AI. Check for mistakes.

Raises:
ValueError: If `value` is of an unsupported type
`(`str`, `int`, `float`, `bool`, and `list[str]`)`
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The Raises: section has malformed inline-code formatting: the supported-type list is wrapped in nested backticks and parentheses, which renders poorly in generated docs. Please rewrite the supported types list without the extra outer backticks/parentheses so it formats cleanly.

Suggested change
`(`str`, `int`, `float`, `bool`, and `list[str]`)`
(`str`, `int`, `float`, `bool`, and `list[str]`).

Copilot uses AI. Check for mistakes.
Comment on lines +502 to +504
flet build ipa \
--info-plist NSCameraUsageDescription="This app uses needs camera access." \
--info-plist UIFileSharingEnabled=true
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The example text "This app uses needs camera access." is grammatically incorrect and is repeated in CLI/TOML/XML examples in this section. Please change it to something like "This app needs camera access." consistently.

Copilot uses AI. Check for mistakes.
def open_settings(e):
result = subprocess.run(
["am", "start", "-n", "com.android.settings/.Settings", "--user", "0"],
shell=False, # default
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

There is a stray tab character before shell=False in the Python example, which makes the snippet look misindented when copied/pasted. Please replace it with spaces to keep formatting consistent.

Suggested change
shell=False, # default
shell=False, # default

Copilot uses AI. Check for mistakes.
Comment on lines 1026 to 1030
- PubSub: cookbook/pub-sub.md
- Read and Write Files: cookbook/read-and-write-files.md
- Session Storage: cookbook/session-storage.md
- Subprocess: cookbook/subprocess.md
- Theming: cookbook/theming.md
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The PR title is scoped to SharedPreferences type support, but this PR also changes CLI build boolean parsing, multiple publish docs pages, adds a new cookbook article, updates a Dart lockfile, and modifies release automation docs. Please either split these into focused PRs or update the PR title/description to reflect the broader scope so reviewers can assess impact appropriately.

Copilot uses AI. Check for mistakes.
@ndonkoHenri ndonkoHenri linked an issue Mar 6, 2026 that may be closed by this pull request
1 task
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.

bug: Webview not working on Android (APK)

2 participants