@ -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" |
||||||
|
} |
||||||
|
} |
@ -1,3 +0,0 @@ |
|||||||
# shared_preferences |
|
||||||
|
|
||||||
A new Flutter FFI plugin project. |
|
@ -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) |
|
@ -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 |
|
@ -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, |
|
||||||
); |
|
||||||
}, |
|
||||||
), |
|
||||||
], |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
), |
|
||||||
); |
|
||||||
} |
|
||||||
} |
|
@ -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 |
|
@ -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; |
|
||||||
}(); |
|
@ -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)>(); |
|
||||||
} |
|
@ -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' |
@ -0,0 +1,3 @@ |
|||||||
|
## 0.0.1 |
||||||
|
|
||||||
|
* TODO: Describe initial release. |
@ -0,0 +1 @@ |
|||||||
|
TODO: Add your license here. |
@ -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,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) |
@ -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 ®istrar) 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 */ |
@ -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 ®istrar) |
||||||
|
{ |
||||||
|
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); |
||||||
|
} |
@ -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 |
||||||
|
|
@ -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) |
||||||
|
|
@ -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 |
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
@ -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 |
@ -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'), |
||||||
|
), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -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, |
||||||
|
); |
||||||
|
}); |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
@ -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.'); |
||||||
|
} |
||||||
|
} |
@ -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'); |
||||||
|
}); |
||||||
|
} |
@ -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'); |
||||||
|
}); |
||||||
|
} |
@ -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) |
|
@ -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; |
|
||||||
} |
|
@ -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); |
|