diff --git a/packages/shared_preferences/shared_preferences_aurora/.gitignore b/packages/shared_preferences/shared_preferences_aurora/.gitignore new file mode 100644 index 0000000..96486fd --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/shared_preferences/shared_preferences_aurora/README.md b/packages/shared_preferences/shared_preferences_aurora/README.md new file mode 100644 index 0000000..5da4423 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/README.md @@ -0,0 +1,46 @@ +# shared_preferences_aurora + +The Aurora implementation of [`shared_preferences`][https://pub.dev/packages/shared_preferences]. + +## Usage + +This package is not an _endorsed_ implementation of `shared_preferences`. +Therefore, you have to include `path_provider_aurora` alongside `shared_preferences` as dependencies in your `pubspec.yaml` file. + +**pubspec.yaml** + +```yaml +dependencies: + shared_preferences: ^2.1.1 + shared_preferences_aurora: ^0.0.0 # @todo Not published +``` + +***.dart** + +```dart +import 'package:shared_preferences/shared_preferences.dart'; + +final SharedPreferences prefs = await SharedPreferences.getInstance(); + +// Save an integer value to 'counter' key. +await prefs.setInt('counter', 10); +// Save an boolean value to 'repeat' key. +await prefs.setBool('repeat', true); +// Save an double value to 'decimal' key. +await prefs.setDouble('decimal', 1.5); +// Save an String value to 'action' key. +await prefs.setString('action', 'Start'); +// Save an list of strings to 'items' key. +await prefs.setStringList('items', ['Earth', 'Moon', 'Sun']); + +// Try reading data from the 'counter' key. If it doesn't exist, returns null. +final int? counter = prefs.getInt('counter'); +// Try reading data from the 'repeat' key. If it doesn't exist, returns null. +final bool? repeat = prefs.getBool('repeat'); +// Try reading data from the 'decimal' key. If it doesn't exist, returns null. +final double? decimal = prefs.getDouble('decimal'); +// Try reading data from the 'action' key. If it doesn't exist, returns null. +final String? action = prefs.getString('action'); +// Try reading data from the 'items' key. If it doesn't exist, returns null. +final List? items = prefs.getStringList('items'); +``` diff --git a/packages/shared_preferences/shared_preferences_aurora/analysis_options.yaml b/packages/shared_preferences/shared_preferences_aurora/analysis_options.yaml new file mode 100644 index 0000000..566c597 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/analysis_options.yaml @@ -0,0 +1,4 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +include: package:flutter_lints/flutter.yaml diff --git a/packages/shared_preferences/shared_preferences_aurora/data/preview.png b/packages/shared_preferences/shared_preferences_aurora/data/preview.png new file mode 100644 index 0000000..c6f0708 Binary files /dev/null and b/packages/shared_preferences/shared_preferences_aurora/data/preview.png differ diff --git a/packages/shared_preferences/shared_preferences_aurora/example/.gitignore b/packages/shared_preferences/shared_preferences_aurora/example/.gitignore new file mode 100644 index 0000000..3db3823 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/.gitignore @@ -0,0 +1,47 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release + +# Aurora generated +/aurora/flutter diff --git a/packages/shared_preferences/shared_preferences_aurora/example/README.md b/packages/shared_preferences/shared_preferences_aurora/example/README.md new file mode 100644 index 0000000..7633274 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/README.md @@ -0,0 +1,22 @@ +# shared_preferences_aurora_example + +Demonstrates how to use the shared_preferences_aurora plugin. + +## Build + +```shell +# Add an alias if it doesn't already exist +alias flutter-aurora=$HOME/.local/opt/flutter-sdk/bin/flutter +# Get dependencies +flutter-aurora pub get +# Run build +flutter-aurora build aurora --release # [--release|--debug|--profile] +``` + +You can collect, sign, run an example on the device with a script located in the `script/build_example.sh` +More information in `build_example.sh`. + +### Preview example + +![preview.png](../data/preview.png) + diff --git a/packages/shared_preferences/shared_preferences_aurora/example/analysis_options.yaml b/packages/shared_preferences/shared_preferences_aurora/example/analysis_options.yaml new file mode 100644 index 0000000..1c55a5e --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/analysis_options.yaml @@ -0,0 +1,4 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/.gitignore b/packages/shared_preferences/shared_preferences_aurora/example/aurora/.gitignore new file mode 100644 index 0000000..d3896c9 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/aurora/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/CMakeLists.txt b/packages/shared_preferences/shared_preferences_aurora/example/aurora/CMakeLists.txt new file mode 100644 index 0000000..781f9e8 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/aurora/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +cmake_minimum_required(VERSION 3.10) +project(com.example.shared_preferences_aurora_example LANGUAGES CXX) + +include(GNUInstallDirs) + +set(BINARY_NAME ${CMAKE_PROJECT_NAME}) +set(FLUTTER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/flutter) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") + +set(CMAKE_SKIP_RPATH OFF) +set(CMAKE_INSTALL_RPATH "\$ORIGIN/../share/${BINARY_NAME}/lib") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder) + +add_executable(${BINARY_NAME} main.cpp ${FLUTTER_DIR}/generated_plugin_registrant.cpp) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::FlutterEmbedder) +target_include_directories(${BINARY_NAME} PRIVATE ${FLUTTER_DIR}) + +include(flutter/generated_plugins.cmake) + +set(PACKAGE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}) +set(DESKTOP_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/applications) +set(ICONS_INSTALL_ROOT_DIR ${CMAKE_INSTALL_DATADIR}/icons/hicolor) + +add_custom_command(TARGET ${BINARY_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libflutter-embedder.so + ${PROJECT_BINARY_DIR}/bundle/lib/libflutter-embedder.so) + +install(FILES ${PROJECT_BINARY_DIR}/bundle/icudtl.dat DESTINATION ${PACKAGE_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/flutter_assets DESTINATION ${PACKAGE_INSTALL_DIR}) +install(DIRECTORY ${PROJECT_BINARY_DIR}/bundle/lib DESTINATION ${PACKAGE_INSTALL_DIR}) + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES desktop/${BINARY_NAME}.desktop DESTINATION ${DESKTOP_INSTALL_DIR}) + +foreach(ICONS_SIZE 86x86 108x108 128x128 172x172) + install(FILES icons/${ICONS_SIZE}.png + RENAME ${BINARY_NAME}.png + DESTINATION ${ICONS_INSTALL_ROOT_DIR}/${ICONS_SIZE}/apps/) +endforeach(ICONS_SIZE) diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/desktop/com.example.shared_preferences_aurora_example.desktop b/packages/shared_preferences/shared_preferences_aurora/example/aurora/desktop/com.example.shared_preferences_aurora_example.desktop new file mode 100644 index 0000000..ebb83d1 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/aurora/desktop/com.example.shared_preferences_aurora_example.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Application +Name=shared_preferences_aurora_example +Comment=Demonstrates how to use the shared_preferences_aurora plugin. +Icon=com.example.shared_preferences_aurora_example +Exec=/usr/bin/com.example.shared_preferences_aurora_example +X-Nemo-Application-Type=silica-qt5 + +[X-Application] +Permissions= +OrganizationName=com.example +ApplicationName=shared_preferences_aurora_example diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/108x108.png b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/108x108.png new file mode 100644 index 0000000..984893d Binary files /dev/null and b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/108x108.png differ diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/128x128.png b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/128x128.png new file mode 100644 index 0000000..2d552ef Binary files /dev/null and b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/128x128.png differ diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/172x172.png b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/172x172.png new file mode 100644 index 0000000..9dc271b Binary files /dev/null and b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/172x172.png differ diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/86x86.png b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/86x86.png new file mode 100644 index 0000000..5923bb1 Binary files /dev/null and b/packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/86x86.png differ diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/main.cpp b/packages/shared_preferences/shared_preferences_aurora/example/aurora/main.cpp new file mode 100644 index 0000000..83f2ca8 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/aurora/main.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +#include +#include "generated_plugin_registrant.h" + +int main(int argc, char *argv[]) { + Application::Initialize(argc, argv); + RegisterPlugins(); + Application::Launch(); + return 0; +} diff --git a/packages/shared_preferences/shared_preferences_aurora/example/aurora/rpm/com.example.shared_preferences_aurora_example.spec b/packages/shared_preferences/shared_preferences_aurora/example/aurora/rpm/com.example.shared_preferences_aurora_example.spec new file mode 100644 index 0000000..a05f586 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/aurora/rpm/com.example.shared_preferences_aurora_example.spec @@ -0,0 +1,31 @@ +%global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$ +%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$ + +Name: com.example.shared_preferences_aurora_example +Summary: Demonstrates how to use the shared_preferences_aurora plugin. +Version: 0.1.0 +Release: 1 +License: Proprietary +Source0: %{name}-%{version}.tar.zst + +BuildRequires: cmake +BuildRequires: pkgconfig(flutter-embedder) + +%description +%{summary}. + +%prep +%autosetup + +%build +%cmake -DCMAKE_BUILD_TYPE=%{_flutter_build_type} +%make_build + +%install +%make_install + +%files +%{_bindir}/%{name} +%{_datadir}/%{name}/* +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/*/apps/%{name}.png diff --git a/packages/shared_preferences/shared_preferences_aurora/example/lib/main.dart b/packages/shared_preferences/shared_preferences_aurora/example/lib/main.dart new file mode 100644 index 0000000..2e79433 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/lib/main.dart @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'package:flutter/material.dart'; +import 'dart:async'; + +import 'package:flutter/services.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + int? _counter; + bool? _repeat; + double? _decimal; + String? _action; + List? _items; + String? _error; + + @override + void initState() { + super.initState(); + initPlatformState(); + } + + Future initPlatformState() async { + try { + SharedPreferences.setPrefix("my_prefix."); + + final SharedPreferences prefs = await SharedPreferences.getInstance(); + + // Save an integer value to 'counter' key. + await prefs.setInt('counter', 10); + // Save an boolean value to 'repeat' key. + await prefs.setBool('repeat', true); + // Save an double value to 'decimal' key. + await prefs.setDouble('decimal', 1.5); + // Save an String value to 'action' key. + await prefs.setString('action', 'Start'); + // Save an list of strings to 'items' key. + await prefs.setStringList('items', ['Earth', 'Moon', 'Sun']); + + // Try reading data from the 'counter' key. If it doesn't exist, returns null. + final int? counter = prefs.getInt('counter'); + // Try reading data from the 'repeat' key. If it doesn't exist, returns null. + final bool? repeat = prefs.getBool('repeat'); + // Try reading data from the 'decimal' key. If it doesn't exist, returns null. + final double? decimal = prefs.getDouble('decimal'); + // Try reading data from the 'action' key. If it doesn't exist, returns null. + final String? action = prefs.getString('action'); + // Try reading data from the 'items' key. If it doesn't exist, returns null. + final List? items = prefs.getStringList('items'); + + setState(() { + _counter = counter; + _repeat = repeat; + _decimal = decimal; + _action = action; + _items = items; + }); + } on PlatformException { + setState(() { + _error = 'Platform exception'; + }); + } + } + + @override + Widget build(BuildContext context) { + const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white); + const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black); + const textStylePath = TextStyle(fontSize: 18, color: Colors.black54); + + const spaceMedium = SizedBox(height: 20); + const spaceSmall = SizedBox(height: 10); + + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Example shared_preferences'), + ), + body: Stack( + children: [ + // Error message + Visibility( + visible: _error != null, + child: Center( + child: Padding( + padding: const EdgeInsets.all(16), + child: Container( + padding: const EdgeInsets.all(20), + decoration: const BoxDecoration( + color: Colors.redAccent, + borderRadius: BorderRadius.all(Radius.circular(10.0)), + ), + child: Text( + _error ?? '', + style: textStyleWhite, + ), + ), + ), + ), + ), + // List directories path + Visibility( + visible: _error == null, + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(16), + child: Center( + child: Column( + children: [ + // Info + Container( + padding: const EdgeInsets.all(20), + decoration: const BoxDecoration( + color: Colors.green, + borderRadius: + BorderRadius.all(Radius.circular(10.0)), + ), + child: const Text( + 'Demo application demonstration implementation of shared_preferences', + style: textStyleWhite, + textAlign: TextAlign.center, + ), + ), + const SizedBox(height: 30), + + const Text( + 'Counter / int', + style: textStyleTitle, + ), + spaceSmall, + Text( + _counter.toString(), + style: textStylePath, + ), + + spaceMedium, + const Text( + 'Repeat / bool', + style: textStyleTitle, + ), + spaceSmall, + Text( + _repeat.toString(), + style: textStylePath, + ), + + spaceMedium, + const Text( + 'Decimal / double', + style: textStyleTitle, + ), + spaceSmall, + Text( + _decimal.toString(), + style: textStylePath, + ), + + spaceMedium, + const Text( + 'Action / String', + style: textStyleTitle, + ), + spaceSmall, + Text( + _action.toString(), + style: textStylePath, + ), + + spaceMedium, + const Text( + 'Items / String List', + style: textStyleTitle, + ), + spaceSmall, + Text( + _items.toString(), + style: textStylePath, + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/packages/shared_preferences/shared_preferences_aurora/example/pubspec.lock b/packages/shared_preferences/shared_preferences_aurora/example/pubspec.lock new file mode 100644 index 0000000..9e61cb7 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/pubspec.lock @@ -0,0 +1,338 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.9.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.16.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.12" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.2" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.15" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.27" + path_provider_aurora: + dependency: transitive + description: + path: "packages/path_provider/path_provider_aurora" + ref: dev + resolved-ref: "7120c2554963ce9e7600730b2657b387d3a86d9c" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.3" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.11" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.7" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + shared_preferences_aurora: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "0.0.1" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.2" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.12" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.2" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.6.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + xdga_directories: + dependency: transitive + description: + path: "packages/xdga_directories" + ref: dev + resolved-ref: "7120c2554963ce9e7600730b2657b387d3a86d9c" + url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git" + source: git + version: "0.0.1" +sdks: + dart: ">=2.18.6 <3.0.0" + flutter: ">=3.3.0" diff --git a/packages/shared_preferences/shared_preferences_aurora/example/pubspec.yaml b/packages/shared_preferences/shared_preferences_aurora/example/pubspec.yaml new file mode 100644 index 0000000..17dde92 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/example/pubspec.yaml @@ -0,0 +1,26 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +name: shared_preferences_aurora_example +description: Demonstrates how to use the shared_preferences_aurora plugin. + +publish_to: 'none' + +environment: + sdk: '>=2.18.6 <3.0.0' + +dependencies: + flutter: + sdk: flutter + shared_preferences: ^2.1.1 + shared_preferences_aurora: + path: ../ + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + uses-material-design: true diff --git a/packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora.dart b/packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora.dart new file mode 100644 index 0000000..e8c606d --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora.dart @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'package:flutter/services.dart'; +import 'package:path_provider_aurora/path_provider_aurora.dart'; +import 'package:shared_preferences_aurora/shared_preferences_aurora_api.dart'; +import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; +import 'package:flutter/foundation.dart'; + +class SharedPreferencesAurora extends SharedPreferencesStorePlatform { + /// Registers this class as the default instance of [SharedPreferencesStorePlatform]. + static void registerWith() { + if (TargetPlatform.aurora == defaultTargetPlatform) { + PathProviderAurora.registerWith(); + SharedPreferencesStorePlatform.instance = SharedPreferencesAurora(); + } + } + + static const String _defaultPrefix = 'flutter.'; + + final SharedPreferencesAuroraApi _api = + SharedPreferencesAuroraApi('.flutter_shared_preferences.json'); + + @override + Future setValue(String valueType, String key, Object value) async { + switch (valueType) { + case 'String': + case 'Bool': + case 'Int': + case 'Double': + case 'StringList': + return _api.setData(key, value); + } + throw PlatformException( + code: 'InvalidOperation', + message: '"$valueType" is not a supported type.'); + } + + @override + Future remove(String key) async => _api.remove(key); + + @override + Future clear() => clearWithPrefix(_defaultPrefix); + + @override + Future> getAll() => getAllWithPrefix(_defaultPrefix); + + @override + Future clearWithPrefix(String prefix) async => + _api.clearWithPrefix(prefix); + + @override + Future> getAllWithPrefix(String prefix) async => + (await _api.getAllWithPrefix(prefix)).cast(); +} diff --git a/packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_api.dart b/packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_api.dart new file mode 100644 index 0000000..4edfd8c --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_api.dart @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023. Open Mobile Platform LLC. + * License: Proprietary. + */ +import 'dart:convert'; +import 'dart:io'; +import 'package:path/path.dart' as p; +import 'package:path_provider/path_provider.dart'; + +class SharedPreferencesAuroraApi { + final JsonDecoder decoder = const JsonDecoder(); + final String fileName; + + SharedPreferencesAuroraApi(this.fileName); + + /// Remove all data by prifix + Future clearWithPrefix(String prefix) async { + final map = await _read(); + final filtered = { + for (final key in map.keys) + if (!key.startsWith(prefix)) key: map[key] + }; + await _save(filtered); + return true; + } + + /// Get all data by prifix + Future> getAllWithPrefix(String prefix) async { + final map = await _read(); + return { + for (final key in map.keys) + if (key.startsWith(prefix)) key: map[key] + }; + } + + /// Remove one value + Future remove(String key) async { + final map = await _read(); + if (map.containsKey(key)) { + map.remove(key); + await _save(map); + return true; + } + return false; + } + + /// Add value and save data + Future setData(String key, dynamic value) async { + final map = await _read(); + map[key] = value; + await _save(map); + return true; + } + + /// Get file with data + Future _getFile() async { + return File(p.join( + (await getTemporaryDirectory()).path, + fileName, + )).create(recursive: true); + } + + /// Read file + Future> _read() async { + final file = await _getFile(); + final value = await file.readAsString(); + return value.isEmpty ? {} : decoder.convert(value); + } + + /// Save data to file + Future _save(Map data) async { + final file = await _getFile(); + final value = json.encode(data); + await file.writeAsString(value); + } +} diff --git a/packages/shared_preferences/shared_preferences_aurora/pubspec.yaml b/packages/shared_preferences/shared_preferences_aurora/pubspec.yaml new file mode 100644 index 0000000..a2d9531 --- /dev/null +++ b/packages/shared_preferences/shared_preferences_aurora/pubspec.yaml @@ -0,0 +1,35 @@ +# Copyright (c) 2023. Open Mobile Platform LLC. +# License: Proprietary. + +name: shared_preferences_aurora +description: The Aurora OS implementation of shared_preferences. +version: 0.0.1 + +environment: + sdk: '>=2.18.6 <3.0.0' + flutter: ">=2.5.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + shared_preferences: ^2.1.1 + shared_preferences_platform_interface: ^2.2.0 + path: ^1.8.2 + path_provider: ^2.0.14 + path_provider_aurora: + git: + url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git + ref: dev + path: packages/path_provider/path_provider_aurora + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + aurora: + dartPluginClass: SharedPreferencesAurora