Browse Source

[shared_preferences] setInt/getInt

merge-requests/2/head
Vitaliy Zarubin 2 years ago
parent
commit
a2eca8b3b7
  1. 59
      .vscode/settings.json
  2. 3
      packages/shared_preferences/README.md
  3. 12
      packages/shared_preferences/aurora/CMakeLists.txt
  4. 12
      packages/shared_preferences/example/aurora/desktop/com.example.shared_preferences_example.desktop
  5. BIN
      packages/shared_preferences/example/defaultuser@
  6. 75
      packages/shared_preferences/example/lib/main.dart
  7. 22
      packages/shared_preferences/ffigen.yaml
  8. 131
      packages/shared_preferences/lib/shared_preferences.dart
  9. 69
      packages/shared_preferences/lib/shared_preferences_bindings_generated.dart
  10. 1
      packages/shared_preferences/shared_preferences_aurora/.gitignore
  11. 30
      packages/shared_preferences/shared_preferences_aurora/.metadata
  12. 3
      packages/shared_preferences/shared_preferences_aurora/CHANGELOG.md
  13. 1
      packages/shared_preferences/shared_preferences_aurora/LICENSE
  14. 15
      packages/shared_preferences/shared_preferences_aurora/README.md
  15. 0
      packages/shared_preferences/shared_preferences_aurora/analysis_options.yaml
  16. 25
      packages/shared_preferences/shared_preferences_aurora/aurora/CMakeLists.txt
  17. 24
      packages/shared_preferences/shared_preferences_aurora/aurora/include/shared_preferences_aurora/shared_preferences_aurora_plugin.h
  18. 59
      packages/shared_preferences/shared_preferences_aurora/aurora/shared_preferences_aurora_plugin.cpp
  19. 0
      packages/shared_preferences/shared_preferences_aurora/example/.gitignore
  20. 4
      packages/shared_preferences/shared_preferences_aurora/example/README.md
  21. 0
      packages/shared_preferences/shared_preferences_aurora/example/analysis_options.yaml
  22. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/.gitignore
  23. 2
      packages/shared_preferences/shared_preferences_aurora/example/aurora/CMakeLists.txt
  24. 12
      packages/shared_preferences/shared_preferences_aurora/example/aurora/desktop/com.example.shared_preferences_aurora_example.desktop
  25. 2
      packages/shared_preferences/shared_preferences_aurora/example/aurora/flutter/generated_plugin_registrant.cpp
  26. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/flutter/generated_plugin_registrant.h
  27. 2
      packages/shared_preferences/shared_preferences_aurora/example/aurora/flutter/generated_plugins.cmake
  28. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/108x108.png
  29. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/128x128.png
  30. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/172x172.png
  31. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/86x86.png
  32. 0
      packages/shared_preferences/shared_preferences_aurora/example/aurora/main.cpp
  33. 4
      packages/shared_preferences/shared_preferences_aurora/example/aurora/rpm/com.example.shared_preferences_aurora_example.spec
  34. 63
      packages/shared_preferences/shared_preferences_aurora/example/lib/main.dart
  35. 4
      packages/shared_preferences/shared_preferences_aurora/example/pubspec.lock
  36. 22
      packages/shared_preferences/shared_preferences_aurora/example/pubspec.yaml
  37. 27
      packages/shared_preferences/shared_preferences_aurora/example/test/widget_test.dart
  38. 11
      packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora.dart
  39. 30
      packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_method_channel.dart
  40. 34
      packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_platform_interface.dart
  41. 12
      packages/shared_preferences/shared_preferences_aurora/pubspec.yaml
  42. 24
      packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_method_channel_test.dart
  43. 29
      packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_test.dart
  44. 17
      packages/shared_preferences/src/CMakeLists.txt
  45. 23
      packages/shared_preferences/src/shared_preferences.c
  46. 30
      packages/shared_preferences/src/shared_preferences.h
  47. 1
      packages/xdga_directories/ffigen.yaml
  48. 12
      script/build_example.sh

59
.vscode/settings.json vendored

@ -0,0 +1,59 @@
{
"files.associations": {
"optional": "cpp",
"system_error": "cpp",
"string": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}

3
packages/shared_preferences/README.md

@ -1,3 +0,0 @@
# shared_preferences
A new Flutter FFI plugin project.

12
packages/shared_preferences/aurora/CMakeLists.txt

@ -1,12 +0,0 @@
cmake_minimum_required(VERSION 3.10)
set(PLUGIN_NAME shared_preferences)
project(${PLUGIN_NAME} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_BINARY_DIR}/shared)

12
packages/shared_preferences/example/aurora/desktop/com.example.shared_preferences_example.desktop

@ -1,12 +0,0 @@
[Desktop Entry]
Type=Application
Name=shared_preferences_example
Comment=Demonstrates how to use the shared_preferences plugin.
Icon=com.example.shared_preferences_example
Exec=/usr/bin/com.example.shared_preferences_example
X-Nemo-Application-Type=silica-qt5
[X-Application]
Permissions=
OrganizationName=com.example
ApplicationName=shared_preferences_example

BIN
packages/shared_preferences/example/defaultuser@

Binary file not shown.

75
packages/shared_preferences/example/lib/main.dart

@ -1,75 +0,0 @@
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:shared_preferences/shared_preferences.dart'
as shared_preferences;
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late int sumResult;
late Future<int> sumAsyncResult;
@override
void initState() {
super.initState();
sumResult = shared_preferences.sum(1, 2);
sumAsyncResult = shared_preferences.sumAsync(3, 4);
}
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(fontSize: 25);
const spacerSmall = SizedBox(height: 10);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Native Packages'),
),
body: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(10),
child: Column(
children: [
const Text(
'This calls a native function through FFI that is shipped as source in the package. '
'The native code is built as part of the Flutter Runner build.',
style: textStyle,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
'sum(1, 2) = $sumResult',
style: textStyle,
textAlign: TextAlign.center,
),
spacerSmall,
FutureBuilder<int>(
future: sumAsyncResult,
builder: (BuildContext context, AsyncSnapshot<int> value) {
final displayValue =
(value.hasData) ? value.data : 'loading';
return Text(
'await sumAsync(3, 4) = $displayValue',
style: textStyle,
textAlign: TextAlign.center,
);
},
),
],
),
),
),
),
);
}
}

22
packages/shared_preferences/ffigen.yaml

@ -1,22 +0,0 @@
# Run with `flutter pub run ffigen --config ffigen.yaml`.
name: SharedPreferencesBindings
llvm-path:
- '/usr/lib/llvm-14/lib/libclang.so' # Ubuntu 22.04
- '/usr/lib/llvm-15/lib/libclang.so' # Ubuntu 23.04
description: |
Bindings for `src/shared_preferences.h`.
Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
output: 'lib/shared_preferences_bindings_generated.dart'
headers:
entry-points:
- 'src/shared_preferences.h'
include-directives:
- 'src/shared_preferences.h'
preamble: |
// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
comments:
style: any
length: full

131
packages/shared_preferences/lib/shared_preferences.dart

@ -1,131 +0,0 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate';
import 'shared_preferences_bindings_generated.dart';
/// A very short-lived native function.
///
/// For very short-lived functions, it is fine to call them on the main isolate.
/// They will block the Dart execution while running the native function, so
/// only do this for native functions which are guaranteed to be short-lived.
int sum(int a, int b) => _bindings.sum(a, b);
/// A longer lived native function, which occupies the thread calling it.
///
/// Do not call these kind of native functions in the main isolate. They will
/// block Dart execution. This will cause dropped frames in Flutter applications.
/// Instead, call these native functions on a separate isolate.
///
/// Modify this to suit your own use case. Example use cases:
///
/// 1. Reuse a single isolate for various different kinds of requests.
/// 2. Use multiple helper isolates for parallel execution.
Future<int> sumAsync(int a, int b) async {
final SendPort helperIsolateSendPort = await _helperIsolateSendPort;
final int requestId = _nextSumRequestId++;
final _SumRequest request = _SumRequest(requestId, a, b);
final Completer<int> completer = Completer<int>();
_sumRequests[requestId] = completer;
helperIsolateSendPort.send(request);
return completer.future;
}
const String _libName = 'shared_preferences';
/// The dynamic library in which the symbols for [SharedPreferencesBindings] can be found.
final DynamicLibrary _dylib = () {
if (Platform.isMacOS || Platform.isIOS) {
return DynamicLibrary.open('$_libName.framework/$_libName');
}
if (Platform.isAndroid || Platform.isLinux) {
return DynamicLibrary.open('lib$_libName.so');
}
if (Platform.isWindows) {
return DynamicLibrary.open('$_libName.dll');
}
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();
/// The bindings to the native functions in [_dylib].
final SharedPreferencesBindings _bindings = SharedPreferencesBindings(_dylib);
/// A request to compute `sum`.
///
/// Typically sent from one isolate to another.
class _SumRequest {
final int id;
final int a;
final int b;
const _SumRequest(this.id, this.a, this.b);
}
/// A response with the result of `sum`.
///
/// Typically sent from one isolate to another.
class _SumResponse {
final int id;
final int result;
const _SumResponse(this.id, this.result);
}
/// Counter to identify [_SumRequest]s and [_SumResponse]s.
int _nextSumRequestId = 0;
/// Mapping from [_SumRequest] `id`s to the completers corresponding to the correct future of the pending request.
final Map<int, Completer<int>> _sumRequests = <int, Completer<int>>{};
/// The SendPort belonging to the helper isolate.
Future<SendPort> _helperIsolateSendPort = () async {
// The helper isolate is going to send us back a SendPort, which we want to
// wait for.
final Completer<SendPort> completer = Completer<SendPort>();
// Receive port on the main isolate to receive messages from the helper.
// We receive two types of messages:
// 1. A port to send messages on.
// 2. Responses to requests we sent.
final ReceivePort receivePort = ReceivePort()
..listen((dynamic data) {
if (data is SendPort) {
// The helper isolate sent us the port on which we can sent it requests.
completer.complete(data);
return;
}
if (data is _SumResponse) {
// The helper isolate sent us a response to a request we sent.
final Completer<int> completer = _sumRequests[data.id]!;
_sumRequests.remove(data.id);
completer.complete(data.result);
return;
}
throw UnsupportedError('Unsupported message type: ${data.runtimeType}');
});
// Start the helper isolate.
await Isolate.spawn((SendPort sendPort) async {
final ReceivePort helperReceivePort = ReceivePort()
..listen((dynamic data) {
// On the helper isolate listen to requests and respond to them.
if (data is _SumRequest) {
final int result = _bindings.sum_long_running(data.a, data.b);
final _SumResponse response = _SumResponse(data.id, result);
sendPort.send(response);
return;
}
throw UnsupportedError('Unsupported message type: ${data.runtimeType}');
});
// Send the the port to the main isolate on which we can receive requests.
sendPort.send(helperReceivePort.sendPort);
}, receivePort.sendPort);
// Wait until the helper isolate has sent us back the SendPort on which we
// can start sending requests.
return completer.future;
}();

69
packages/shared_preferences/lib/shared_preferences_bindings_generated.dart

@ -1,69 +0,0 @@
// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
// ignore_for_file: non_constant_identifier_names
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;
/// Bindings for `src/shared_preferences.h`.
///
/// Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`.
///
class SharedPreferencesBindings {
/// Holds the symbol lookup function.
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
_lookup;
/// The symbols are looked up in [dynamicLibrary].
SharedPreferencesBindings(ffi.DynamicLibrary dynamicLibrary)
: _lookup = dynamicLibrary.lookup;
/// The symbols are looked up with [lookup].
SharedPreferencesBindings.fromLookup(
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
lookup)
: _lookup = lookup;
/// A very short-lived native function.
///
/// For very short-lived functions, it is fine to call them on the main isolate.
/// They will block the Dart execution while running the native function, so
/// only do this for native functions which are guaranteed to be short-lived.
int sum(
int a,
int b,
) {
return _sum(
a,
b,
);
}
late final _sumPtr =
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>>(
'sum');
late final _sum = _sumPtr.asFunction<int Function(int, int)>();
/// A longer lived native function, which occupies the thread calling it.
///
/// Do not call these kind of native functions in the main isolate. They will
/// block Dart execution. This will cause dropped frames in Flutter applications.
/// Instead, call these native functions on a separate isolate.
int sum_long_running(
int a,
int b,
) {
return _sum_long_running(
a,
b,
);
}
late final _sum_long_runningPtr =
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>>(
'sum_long_running');
late final _sum_long_running =
_sum_long_runningPtr.asFunction<int Function(int, int)>();
}

1
packages/shared_preferences/.gitignore → packages/shared_preferences/shared_preferences_aurora/.gitignore vendored

@ -28,4 +28,3 @@ migrate_working_dir/
.dart_tool/ .dart_tool/
.packages .packages
build/ build/
.metadata

30
packages/shared_preferences/shared_preferences_aurora/.metadata

@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.
version:
revision: 135454af32477f815a7525073027a3ff9eff1bfd
channel: unknown
project_type: plugin
# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
- platform: aurora
create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
# User provided section
# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'

3
packages/shared_preferences/shared_preferences_aurora/CHANGELOG.md

@ -0,0 +1,3 @@
## 0.0.1
* TODO: Describe initial release.

1
packages/shared_preferences/shared_preferences_aurora/LICENSE

@ -0,0 +1 @@
TODO: Add your license here.

15
packages/shared_preferences/shared_preferences_aurora/README.md

@ -0,0 +1,15 @@
# shared_preferences_aurora
A new Flutter plugin project.
## Getting Started
This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
For help getting started with Flutter development, view the
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

0
packages/shared_preferences/analysis_options.yaml → packages/shared_preferences/shared_preferences_aurora/analysis_options.yaml

25
packages/shared_preferences/shared_preferences_aurora/aurora/CMakeLists.txt

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME shared_preferences_aurora)
set(PLUGIN_NAME shared_preferences_aurora_platform_plugin)
project(${PROJECT_NAME} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
find_package(PkgConfig REQUIRED)
pkg_check_modules(FlutterEmbedder REQUIRED IMPORTED_TARGET flutter-embedder)
pkg_check_modules(Qt5Core REQUIRED IMPORTED_TARGET Qt5Core)
add_library(${PLUGIN_NAME} SHARED shared_preferences_aurora_plugin.cpp)
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::FlutterEmbedder)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::Qt5Core)
target_include_directories(${PLUGIN_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(${PLUGIN_NAME} PRIVATE PLUGIN_IMPL)

24
packages/shared_preferences/shared_preferences_aurora/aurora/include/shared_preferences_aurora/shared_preferences_aurora_plugin.h

@ -0,0 +1,24 @@
#ifndef FLUTTER_PLUGIN_SHARED_PREFERENCES_AURORA_PLUGIN_H
#define FLUTTER_PLUGIN_SHARED_PREFERENCES_AURORA_PLUGIN_H
#include <flutter/plugin-interface.h>
#ifdef PLUGIN_IMPL
#define PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define PLUGIN_EXPORT
#endif
class PLUGIN_EXPORT SharedPreferencesAuroraPlugin final : public PluginInterface
{
public:
void RegisterWithRegistrar(PluginRegistrar &registrar) override;
private:
void onMethodCall(const MethodCall &call);
void onGetInt(const MethodCall &call);
void onSetInt(const MethodCall &call);
void unimplemented(const MethodCall &call);
};
#endif /* FLUTTER_PLUGIN_SHARED_PREFERENCES_AURORA_PLUGIN_H */

59
packages/shared_preferences/shared_preferences_aurora/aurora/shared_preferences_aurora_plugin.cpp

@ -0,0 +1,59 @@
#include <shared_preferences_aurora/shared_preferences_aurora_plugin.h>
#include <flutter/method-channel.h>
#include <flutter/application.h>
#include <QSettings>
#include <QDebug>
void SharedPreferencesAuroraPlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
registrar.RegisterMethodChannel("shared_preferences_aurora",
MethodCodecType::Standard,
[this](const MethodCall &call) { this->onMethodCall(call); });
}
void SharedPreferencesAuroraPlugin::onMethodCall(const MethodCall &call)
{
const auto &method = call.GetMethod();
if (method == "getInt") {
onGetInt(call);
return;
}
else if (method == "setInt") {
onSetInt(call);
return;
}
unimplemented(call);
}
void SharedPreferencesAuroraPlugin::onGetInt(const MethodCall &call)
{
// get arguments
std::string key = call.GetArguments()["key"].GetString();
int value = call.GetArguments()["value"].GetInt();
// init settings
const auto [orgname, appname] = Application::GetID();
QSettings settings(QString::fromStdString(orgname), QString::fromStdString(appname));
// send response
call.SendSuccessResponse(settings.value(QString::fromStdString(key), value).toInt());
}
void SharedPreferencesAuroraPlugin::onSetInt(const MethodCall &call)
{
// get arguments
std::string key = call.GetArguments()["key"].GetString();
int value = call.GetArguments()["value"].GetInt();
// init settings
const auto [orgname, appname] = Application::GetID();
QSettings settings(QString::fromStdString(orgname), QString::fromStdString(appname));
// save
settings.setValue(QString::fromStdString(key), value);
// send response
call.SendSuccessResponse(true);
}
void SharedPreferencesAuroraPlugin::unimplemented(const MethodCall &call)
{
call.SendSuccessResponse(nullptr);
}

0
packages/shared_preferences/example/.gitignore → packages/shared_preferences/shared_preferences_aurora/example/.gitignore vendored

4
packages/shared_preferences/example/README.md → packages/shared_preferences/shared_preferences_aurora/example/README.md

@ -1,6 +1,6 @@
# shared_preferences_example # shared_preferences_aurora_example
Demonstrates how to use the shared_preferences plugin. Demonstrates how to use the shared_preferences_aurora plugin.
## Getting Started ## Getting Started

0
packages/shared_preferences/example/analysis_options.yaml → packages/shared_preferences/shared_preferences_aurora/example/analysis_options.yaml

0
packages/shared_preferences/example/aurora/.gitignore → packages/shared_preferences/shared_preferences_aurora/example/aurora/.gitignore vendored

2
packages/shared_preferences/example/aurora/CMakeLists.txt → packages/shared_preferences/shared_preferences_aurora/example/aurora/CMakeLists.txt

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(com.example.shared_preferences_example LANGUAGES CXX) project(com.example.shared_preferences_aurora_example LANGUAGES CXX)
include(GNUInstallDirs) include(GNUInstallDirs)

12
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

2
packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.cpp → packages/shared_preferences/shared_preferences_aurora/example/aurora/flutter/generated_plugin_registrant.cpp

@ -5,10 +5,12 @@
// clang-format off // clang-format off
#include <flutter/application.h> #include <flutter/application.h>
#include <shared_preferences_aurora/shared_preferences_aurora_plugin.h>
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
void RegisterPlugins() { void RegisterPlugins() {
Application::RegisterPlugins({ Application::RegisterPlugins({
std::make_shared<SharedPreferencesAuroraPlugin>(),
}); });
} }

0
packages/shared_preferences/example/aurora/flutter/generated_plugin_registrant.h → packages/shared_preferences/shared_preferences_aurora/example/aurora/flutter/generated_plugin_registrant.h

2
packages/shared_preferences/example/aurora/flutter/generated_plugins.cmake → packages/shared_preferences/shared_preferences_aurora/example/aurora/flutter/generated_plugins.cmake

@ -15,10 +15,10 @@ function(add_library TARGET)
endfunction() endfunction()
list(APPEND FLUTTER_PLATFORM_PLUGIN_LIST list(APPEND FLUTTER_PLATFORM_PLUGIN_LIST
shared_preferences_aurora
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST
shared_preferences
) )
foreach(PLUGIN ${FLUTTER_PLATFORM_PLUGIN_LIST}) foreach(PLUGIN ${FLUTTER_PLATFORM_PLUGIN_LIST})

0
packages/shared_preferences/example/aurora/icons/108x108.png → packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/108x108.png

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

0
packages/shared_preferences/example/aurora/icons/128x128.png → packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/128x128.png

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

0
packages/shared_preferences/example/aurora/icons/172x172.png → packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/172x172.png

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

0
packages/shared_preferences/example/aurora/icons/86x86.png → packages/shared_preferences/shared_preferences_aurora/example/aurora/icons/86x86.png

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

0
packages/shared_preferences/example/aurora/main.cpp → packages/shared_preferences/shared_preferences_aurora/example/aurora/main.cpp

4
packages/shared_preferences/example/aurora/rpm/com.example.shared_preferences_example.spec → packages/shared_preferences/shared_preferences_aurora/example/aurora/rpm/com.example.shared_preferences_aurora_example.spec

@ -1,8 +1,8 @@
%global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$ %global __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$
%global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$ %global __requires_exclude ^lib(dconf|flutter-embedder|maliit-glib|appmanifest-.+|.+_platform_plugin)\\.so.*$
Name: com.example.shared_preferences_example Name: com.example.shared_preferences_aurora_example
Summary: Demonstrates how to use the shared_preferences plugin. Summary: Demonstrates how to use the shared_preferences_aurora plugin.
Version: 0.1.0 Version: 0.1.0
Release: 1 Release: 1
License: Proprietary License: Proprietary

63
packages/shared_preferences/shared_preferences_aurora/example/lib/main.dart

@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:shared_preferences_aurora/shared_preferences_aurora.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _platformVersion = -1;
final _sharedPreferencesAuroraPlugin = SharedPreferencesAurora();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
int platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
await _sharedPreferencesAuroraPlugin.setInt('key', 222);
platformVersion = await _sharedPreferencesAuroraPlugin.getInt('key', -99);
} on PlatformException {
platformVersion = -2;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
),
),
);
}
}

4
packages/shared_preferences/example/pubspec.lock → packages/shared_preferences/shared_preferences_aurora/example/pubspec.lock

@ -109,7 +109,7 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
shared_preferences: shared_preferences_aurora:
dependency: "direct main" dependency: "direct main"
description: description:
path: ".." path: ".."
@ -172,4 +172,4 @@ packages:
version: "2.1.2" version: "2.1.2"
sdks: sdks:
dart: ">=2.18.6 <3.0.0" dart: ">=2.18.6 <3.0.0"
flutter: ">=2.11.0" flutter: ">=2.5.0"

22
packages/shared_preferences/example/pubspec.yaml → packages/shared_preferences/shared_preferences_aurora/example/pubspec.yaml

@ -1,24 +1,10 @@
name: shared_preferences_example name: shared_preferences_aurora_example
description: Demonstrates how to use the shared_preferences plugin. description: Demonstrates how to use the shared_preferences_aurora plugin.
# The following line prevents the package from being accidentally published to # The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages. # pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
environment: environment:
sdk: '>=2.18.6 <3.0.0' sdk: '>=2.18.6 <3.0.0'
@ -32,9 +18,9 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
shared_preferences: shared_preferences_aurora:
# When depending on this package from a real application you should use: # When depending on this package from a real application you should use:
# shared_preferences: ^x.y.z # shared_preferences_aurora: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints # See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on # The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version. # the parent directory to use the current plugin's version.

27
packages/shared_preferences/shared_preferences_aurora/example/test/widget_test.dart

@ -0,0 +1,27 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_aurora_example/main.dart';
void main() {
testWidgets('Verify Platform version', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
});
}

11
packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora.dart

@ -0,0 +1,11 @@
import 'shared_preferences_aurora_platform_interface.dart';
class SharedPreferencesAurora {
Future<int> getInt(String key, int value) {
return SharedPreferencesAuroraPlatform.instance.getInt(key, value);
}
Future<bool> setInt(String key, int value) {
return SharedPreferencesAuroraPlatform.instance.setInt(key, value);
}
}

30
packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_method_channel.dart

@ -0,0 +1,30 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'shared_preferences_aurora_platform_interface.dart';
/// An implementation of [SharedPreferencesAuroraPlatform] that uses method channels.
class MethodChannelSharedPreferencesAurora
extends SharedPreferencesAuroraPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('shared_preferences_aurora');
@override
Future<int> getInt(String key, int value) async {
final result = await methodChannel.invokeMethod<int?>('getInt', {
'key': key,
'value': value,
});
return result ?? value;
}
@override
Future<bool> setInt(String key, int value) async {
return await methodChannel.invokeMethod<bool?>('setInt', {
'key': key,
'value': value,
}) ??
false;
}
}

34
packages/shared_preferences/shared_preferences_aurora/lib/shared_preferences_aurora_platform_interface.dart

@ -0,0 +1,34 @@
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'shared_preferences_aurora_method_channel.dart';
abstract class SharedPreferencesAuroraPlatform extends PlatformInterface {
/// Constructs a SharedPreferencesAuroraPlatform.
SharedPreferencesAuroraPlatform() : super(token: _token);
static final Object _token = Object();
static SharedPreferencesAuroraPlatform _instance =
MethodChannelSharedPreferencesAurora();
/// The default instance of [SharedPreferencesAuroraPlatform] to use.
///
/// Defaults to [MethodChannelSharedPreferencesAurora].
static SharedPreferencesAuroraPlatform get instance => _instance;
/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [SharedPreferencesAuroraPlatform] when
/// they register themselves.
static set instance(SharedPreferencesAuroraPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Future<int> getInt(String key, int value) {
throw UnimplementedError('getInt() has not been implemented.');
}
Future<bool> setInt(String key, int value) {
throw UnimplementedError('setInt() has not been implemented.');
}
}

12
packages/shared_preferences/pubspec.yaml → packages/shared_preferences/shared_preferences_aurora/pubspec.yaml

@ -1,11 +1,11 @@
name: shared_preferences name: shared_preferences_aurora
description: A new Flutter FFI plugin project. description: A new Flutter plugin project.
version: 0.0.1 version: 0.0.1
homepage: homepage:
environment: environment:
sdk: '>=2.18.6 <3.0.0' sdk: '>=2.18.6 <3.0.0'
flutter: ">=2.11.0" flutter: ">=2.5.0"
dependencies: dependencies:
flutter: flutter:
@ -13,8 +13,6 @@ dependencies:
plugin_platform_interface: ^2.0.2 plugin_platform_interface: ^2.0.2
dev_dependencies: dev_dependencies:
ffi: ^1.2.1
ffigen: ^5.0.1
flutter_test: flutter_test:
sdk: flutter sdk: flutter
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
@ -34,12 +32,10 @@ flutter:
# This is required for using `dart:ffi`. # This is required for using `dart:ffi`.
# All these are used by the tooling to maintain consistency when # All these are used by the tooling to maintain consistency when
# adding or updating assets for this project. # adding or updating assets for this project.
#
# Please refer to README.md for a detailed explanation.
plugin: plugin:
platforms: platforms:
aurora: aurora:
ffiPlugin: true pluginClass: SharedPreferencesAuroraPlugin
# To add assets to your plugin package, add an assets section, like this: # To add assets to your plugin package, add an assets section, like this:
# assets: # assets:

24
packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_method_channel_test.dart

@ -0,0 +1,24 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_aurora/shared_preferences_aurora_method_channel.dart';
void main() {
MethodChannelSharedPreferencesAurora platform = MethodChannelSharedPreferencesAurora();
const MethodChannel channel = MethodChannel('shared_preferences_aurora');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});
tearDown(() {
channel.setMockMethodCallHandler(null);
});
test('getPlatformVersion', () async {
expect(await platform.getPlatformVersion(), '42');
});
}

29
packages/shared_preferences/shared_preferences_aurora/test/shared_preferences_aurora_test.dart

@ -0,0 +1,29 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_aurora/shared_preferences_aurora.dart';
import 'package:shared_preferences_aurora/shared_preferences_aurora_platform_interface.dart';
import 'package:shared_preferences_aurora/shared_preferences_aurora_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockSharedPreferencesAuroraPlatform
with MockPlatformInterfaceMixin
implements SharedPreferencesAuroraPlatform {
@override
Future<String?> getPlatformVersion() => Future.value('42');
}
void main() {
final SharedPreferencesAuroraPlatform initialPlatform = SharedPreferencesAuroraPlatform.instance;
test('$MethodChannelSharedPreferencesAurora is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelSharedPreferencesAurora>());
});
test('getPlatformVersion', () async {
SharedPreferencesAurora sharedPreferencesAuroraPlugin = SharedPreferencesAurora();
MockSharedPreferencesAuroraPlatform fakePlatform = MockSharedPreferencesAuroraPlatform();
SharedPreferencesAuroraPlatform.instance = fakePlatform;
expect(await sharedPreferencesAuroraPlugin.getPlatformVersion(), '42');
});
}

17
packages/shared_preferences/src/CMakeLists.txt

@ -1,17 +0,0 @@
# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)
project(shared_preferences_library VERSION 0.0.1 LANGUAGES C)
add_library(shared_preferences SHARED
"shared_preferences.c"
)
set_target_properties(shared_preferences PROPERTIES
PUBLIC_HEADER shared_preferences.h
OUTPUT_NAME "shared_preferences"
)
target_compile_definitions(shared_preferences PUBLIC DART_SHARED_LIB)

23
packages/shared_preferences/src/shared_preferences.c

@ -1,23 +0,0 @@
#include "shared_preferences.h"
// A very short-lived native function.
//
// For very short-lived functions, it is fine to call them on the main isolate.
// They will block the Dart execution while running the native function, so
// only do this for native functions which are guaranteed to be short-lived.
FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b) { return a + b; }
// A longer-lived native function, which occupies the thread calling it.
//
// Do not call these kind of native functions in the main isolate. They will
// block Dart execution. This will cause dropped frames in Flutter applications.
// Instead, call these native functions on a separate isolate.
FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b) {
// Simulate work.
#if _WIN32
Sleep(5000);
#else
usleep(5000 * 1000);
#endif
return a + b;
}

30
packages/shared_preferences/src/shared_preferences.h

@ -1,30 +0,0 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#if _WIN32
#include <windows.h>
#else
#include <pthread.h>
#include <unistd.h>
#endif
#if _WIN32
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FFI_PLUGIN_EXPORT
#endif
// A very short-lived native function.
//
// For very short-lived functions, it is fine to call them on the main isolate.
// They will block the Dart execution while running the native function, so
// only do this for native functions which are guaranteed to be short-lived.
FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b);
// A longer lived native function, which occupies the thread calling it.
//
// Do not call these kind of native functions in the main isolate. They will
// block Dart execution. This will cause dropped frames in Flutter applications.
// Instead, call these native functions on a separate isolate.
FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b);

1
packages/xdga_directories/ffigen.yaml

@ -2,6 +2,7 @@
name: XdgaDirectoriesBindings name: XdgaDirectoriesBindings
llvm-path: llvm-path:
- '/usr/lib/llvm-14/lib/libclang.so' # Ubuntu 22.04 - '/usr/lib/llvm-14/lib/libclang.so' # Ubuntu 22.04
- '/usr/lib/llvm-15/lib/libclang.so' # Ubuntu 23.04
description: | description: |
Bindings for `src/xdga_directories.h`. Bindings for `src/xdga_directories.h`.

12
script/build_example.sh

@ -43,7 +43,11 @@ else
## Open example dir ## Open example dir
cd "example" || exit cd "example" || exit
## Build aurora example app ## Build aurora example app
$FLATTER build aurora --release {
$FLATTER build aurora --release
} || {
exit 1;
}
fi fi
if [ -n "$sign" ]; then if [ -n "$sign" ]; then
@ -72,9 +76,11 @@ fi
if [ -n "$device" ]; then if [ -n "$device" ]; then
IFS=':' read -ra ADDR <<< "$device" IFS=':' read -ra ADDR <<< "$device"
IFS='/' read -ra ADDP <<< "$package"
D_IP="${ADDR[0]}" D_IP="${ADDR[0]}"
D_PASS="${ADDR[1]}" D_PASS="${ADDR[1]}"
APP_KEY="${ADDP[-1]}"
# shellcheck disable=SC2012 # shellcheck disable=SC2012
rpm=$(ls "$PWD"/build/aurora/arm/release/RPMS/*.rpm | sort -r | head -n 1) rpm=$(ls "$PWD"/build/aurora/arm/release/RPMS/*.rpm | sort -r | head -n 1)
@ -83,8 +89,8 @@ if [ -n "$device" ]; then
scp "$rpm" defaultuser@"$D_IP:/home/defaultuser/Downloads" scp "$rpm" defaultuser@"$D_IP:/home/defaultuser/Downloads"
# install rpm # install rpm
ssh -t defaultuser@$D_IP "echo $D_PASS | devel-su pkcon -y install-local /home/defaultuser/Downloads/*$package*.rpm" ssh -t defaultuser@$D_IP "echo $D_PASS | devel-su pkcon -y install-local /home/defaultuser/Downloads/*$APP_KEY*.rpm"
# run application # run application
ssh -t defaultuser@$D_IP "/usr/bin/com.example.${package}_example" ssh -t defaultuser@$D_IP "/usr/bin/com.example.${APP_KEY}_example"
fi fi
Loading…
Cancel
Save