Skip to content

Commit

Permalink
[shared_preferences] Switch to new analysis options (#287)
Browse files Browse the repository at this point in the history
* [shared_preferences] Switch to new analysis options

* Resolve analyzer warnings
  • Loading branch information
swift-kim authored Dec 7, 2021
1 parent d9019d6 commit c9f7432
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 113 deletions.
32 changes: 19 additions & 13 deletions packages/shared_preferences/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
## 1.0.0

* Initial release
* Initial release.

## 1.0.1

* Update shared_preferences to 0.5.12+4
* Update platform interface to 1.0.4
* Migrate to Tizen 4.0
* Update shared_preferences to 0.5.12+4.
* Update shared_preferences_platform_interface to 1.0.4.
* Migrate to Tizen 4.0.

## 2.0.0

* Update Dart and Flutter SDK constraints
* Update Flutter copyright information
* Update example and integration_test
* Update platform interface to 2.0.0
* Organize dev_dependencies
* Migrate to ffi 1.0.0
* Migrate to null safety
* Remove unused `PreferenceIsExisiting` from the implementation
* Update Dart and Flutter SDK constraints.
* Update Flutter copyright information.
* Update the example app and integration_test.
* Update shared_preferences_platform_interface to 2.0.0.
* Organize dev_dependencies.
* Migrate to ffi 1.0.0.
* Migrate to null safety.
* Remove unused `PreferenceIsExisiting` from the implementation.

## 2.0.1

* Fix memory leaks
* Fix memory leaks.

## 2.0.2

* Update shared_preferences to 2.0.9.
* Switch to new analysis options.
* Update integration_test.
4 changes: 2 additions & 2 deletions packages/shared_preferences/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This package is not an _endorsed_ implementation of `shared_preferences`. Theref

```yaml
dependencies:
shared_preferences: ^2.0.5
shared_preferences_tizen: ^2.0.1
shared_preferences: ^2.0.9
shared_preferences_tizen: ^2.0.2
```
Then you can import `shared_preferences` in your Dart code:
Expand Down
1 change: 0 additions & 1 deletion packages/shared_preferences/analysis_options.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion packages/shared_preferences/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Demonstrates how to use the shared_preferences_tizen plugin.

## Getting Started

To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:integration_test/integration_test.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('$SharedPreferences', () {
const Map<String, dynamic> kTestValues = <String, dynamic>{
'flutter.String': 'hello world',
'flutter.bool': true,
'flutter.int': 42,
'flutter.double': 3.14159,
'flutter.List': <String>['foo', 'bar'],
};
const String testString = 'hello world';
const bool testBool = true;
const int testInt = 42;
const double testDouble = 3.14159;
const List<String> testList = <String>['foo', 'bar'];

const Map<String, dynamic> kTestValues2 = <String, dynamic>{
'flutter.String': 'goodbye world',
'flutter.bool': false,
'flutter.int': 1337,
'flutter.double': 2.71828,
'flutter.List': <String>['baz', 'quox'],
};
const String testString2 = 'goodbye world';
const bool testBool2 = false;
const int testInt2 = 1337;
const double testDouble2 = 2.71828;
const List<String> testList2 = <String>['baz', 'quox'];

SharedPreferences preferences;
late SharedPreferences preferences;

setUp(() async {
preferences = await SharedPreferences.getInstance();
Expand All @@ -54,43 +47,36 @@ void main() {

testWidgets('writing', (WidgetTester _) async {
await Future.wait(<Future<bool>>[
preferences.setString(
'String', kTestValues2['flutter.String'] as String),
preferences.setBool('bool', kTestValues2['flutter.bool'] as bool),
preferences.setInt('int', kTestValues2['flutter.int'] as int),
preferences.setDouble(
'double', kTestValues2['flutter.double'] as double),
preferences.setStringList(
'List', kTestValues2['flutter.List'] as List<String>)
preferences.setString('String', testString2),
preferences.setBool('bool', testBool2),
preferences.setInt('int', testInt2),
preferences.setDouble('double', testDouble2),
preferences.setStringList('List', testList2)
]);
expect(preferences.getString('String'), kTestValues2['flutter.String']);
expect(preferences.getBool('bool'), kTestValues2['flutter.bool']);
expect(preferences.getInt('int'), kTestValues2['flutter.int']);
expect(preferences.getDouble('double'), kTestValues2['flutter.double']);
expect(preferences.getStringList('List'), kTestValues2['flutter.List']);
expect(preferences.getString('String'), testString2);
expect(preferences.getBool('bool'), testBool2);
expect(preferences.getInt('int'), testInt2);
expect(preferences.getDouble('double'), testDouble2);
expect(preferences.getStringList('List'), testList2);
});

testWidgets('removing', (WidgetTester _) async {
const String key = 'testKey';
await preferences.setString(key, kTestValues['flutter.String'] as String);
await preferences.setBool(key, kTestValues['flutter.bool'] as bool);
await preferences.setInt(key, kTestValues['flutter.int'] as int);
await preferences.setDouble(key, kTestValues['flutter.double'] as double);
await preferences.setStringList(
key, kTestValues['flutter.List'] as List<String>);
await preferences.setString(key, testString);
await preferences.setBool(key, testBool);
await preferences.setInt(key, testInt);
await preferences.setDouble(key, testDouble);
await preferences.setStringList(key, testList);
await preferences.remove(key);
expect(preferences.get('testKey'), isNull);
});

testWidgets('clearing', (WidgetTester _) async {
await preferences.setString(
'String', kTestValues['flutter.String'] as String);
await preferences.setBool('bool', kTestValues['flutter.bool'] as bool);
await preferences.setInt('int', kTestValues['flutter.int'] as int);
await preferences.setDouble(
'double', kTestValues['flutter.double'] as double);
await preferences.setStringList(
'List', kTestValues['flutter.List'] as List<String>);
await preferences.setString('String', testString);
await preferences.setBool('bool', testBool);
await preferences.setInt('int', testInt);
await preferences.setDouble('double', testDouble);
await preferences.setStringList('List', testList);
await preferences.clear();
expect(preferences.getString('String'), null);
expect(preferences.getBool('bool'), null);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared_preferences/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish_to: "none"
dependencies:
flutter:
sdk: flutter
shared_preferences: ^2.0.5
shared_preferences: ^2.0.9
shared_preferences_tizen:
path: ../

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
2 changes: 1 addition & 1 deletion packages/shared_preferences/example/tizen/Runner.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Tizen.NET.Sdk/1.1.5">
<Project Sdk="Tizen.NET.Sdk/1.1.7">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
3 changes: 1 addition & 2 deletions packages/shared_preferences/example/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.tizen.shared_preferences_tizen_example" version="1.0.0" api-version="4.0" xmlns="http://tizen.org/ns/packages">
<profile name="common"/>
<ui-application appid="org.tizen.shared_preferences_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4" launch_mode="single">
<ui-application appid="org.tizen.shared_preferences_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="4">
<label>shared_preferences_tizen_example</label>
<icon>ic_launcher.png</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true"/>
<metadata key="http://tizen.org/metadata/direct-launch" value="yes"/>
</ui-application>
<feature name="http://tizen.org/feature/screen.size.all"/>
</manifest>
56 changes: 29 additions & 27 deletions packages/shared_preferences/lib/src/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,41 @@ import 'types.dart';

class _PreferenceBindings {
_PreferenceBindings() {
_lib = DynamicLibrary.open('libcapi-appfw-preference.so.0');
final DynamicLibrary lib =
DynamicLibrary.open('libcapi-appfw-preference.so.0');

setInt = _lib.lookupFunction<preference_set_int_native_t, PreferenceSetInt>(
setInt = lib.lookupFunction<PreferenceSetIntNative, PreferenceSetInt>(
'preference_set_int');
getInt = _lib.lookupFunction<preference_get_int_native_t, PreferenceGetInt>(
getInt = lib.lookupFunction<PreferenceGetIntNative, PreferenceGetInt>(
'preference_get_int');

setDouble = _lib.lookupFunction<preference_set_double_native_t,
PreferenceSetDouble>('preference_set_double');
getDouble = _lib.lookupFunction<preference_get_double_native_t,
PreferenceGetDouble>('preference_get_double');

setString = _lib.lookupFunction<preference_set_string_native_t,
PreferenceSetString>('preference_set_string');
getString = _lib.lookupFunction<preference_get_string_native_t,
PreferenceGetString>('preference_get_string');

setBoolean = _lib.lookupFunction<preference_set_boolean_native_t,
PreferenceSetBoolean>('preference_set_boolean');
getBoolean = _lib.lookupFunction<preference_get_boolean_native_t,
PreferenceGetBoolean>('preference_get_boolean');

remove = _lib.lookupFunction<preference_remove_native_t, PreferenceRemove>(
setDouble =
lib.lookupFunction<PreferenceSetDoubleNative, PreferenceSetDouble>(
'preference_set_double');
getDouble =
lib.lookupFunction<PreferenceGetDoubleNative, PreferenceGetDouble>(
'preference_get_double');
setString =
lib.lookupFunction<PreferenceSetStringNative, PreferenceSetString>(
'preference_set_string');
getString =
lib.lookupFunction<PreferenceGetStringNative, PreferenceGetString>(
'preference_get_string');
setBoolean =
lib.lookupFunction<PreferenceSetBooleanNative, PreferenceSetBoolean>(
'preference_set_boolean');
getBoolean =
lib.lookupFunction<PreferenceGetBooleanNative, PreferenceGetBoolean>(
'preference_get_boolean');
remove = lib.lookupFunction<PreferenceRemoveNative, PreferenceRemove>(
'preference_remove');

removeAll = _lib.lookupFunction<preference_remove_all_native_t,
PreferenceRemoveAll>('preference_remove_all');

foreachItem = _lib.lookupFunction<preference_foreach_item_native_t,
PreferenceForeachItem>('preference_foreach_item');
removeAll =
lib.lookupFunction<PreferenceRemoveAllNative, PreferenceRemoveAll>(
'preference_remove_all');
foreachItem =
lib.lookupFunction<PreferenceForeachItemNative, PreferenceForeachItem>(
'preference_foreach_item');
}

late DynamicLibrary _lib;
late PreferenceSetInt setInt;
late PreferenceGetInt getInt;
late PreferenceSetDouble setDouble;
Expand Down
29 changes: 14 additions & 15 deletions packages/shared_preferences/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,65 @@ import 'dart:ffi';
import 'package:ffi/ffi.dart';

// int preference_set_int (const char *key, int value)
typedef preference_set_int_native_t = Int32 Function(
Pointer<Utf8> key, Int32 value);
typedef PreferenceSetIntNative = Int32 Function(Pointer<Utf8> key, Int32 value);
typedef PreferenceSetInt = int Function(Pointer<Utf8> key, int value);

// int preference_get_int (const char *key, int *value)
typedef preference_get_int_native_t = Int32 Function(
typedef PreferenceGetIntNative = Int32 Function(
Pointer<Utf8> key, Pointer<Int32> value);
typedef PreferenceGetInt = int Function(
Pointer<Utf8> key, Pointer<Int32> value);

// int preference_set_double (const char *key, double value)
typedef preference_set_double_native_t = Int32 Function(
typedef PreferenceSetDoubleNative = Int32 Function(
Pointer<Utf8> key, Double value);
typedef PreferenceSetDouble = int Function(Pointer<Utf8> key, double value);

// int preference_get_double (const char *key, double *value)
typedef preference_get_double_native_t = Int32 Function(
typedef PreferenceGetDoubleNative = Int32 Function(
Pointer<Utf8> key, Pointer<Double> value);
typedef PreferenceGetDouble = int Function(
Pointer<Utf8> key, Pointer<Double> value);

// int preference_set_string (const char *key, const char *value)
typedef preference_set_string_native_t = Int32 Function(
typedef PreferenceSetStringNative = Int32 Function(
Pointer<Utf8> key, Pointer<Utf8> value);
typedef PreferenceSetString = int Function(
Pointer<Utf8> key, Pointer<Utf8> value);

// int preference_get_string (const char *key, char **value)
typedef preference_get_string_native_t = Int32 Function(
typedef PreferenceGetStringNative = Int32 Function(
Pointer<Utf8> key, Pointer<Pointer<Utf8>> value);
typedef PreferenceGetString = int Function(
Pointer<Utf8> key, Pointer<Pointer<Utf8>> value);

// int preference_set_boolean (const char *key, bool value)
typedef preference_set_boolean_native_t = Int32 Function(
typedef PreferenceSetBooleanNative = Int32 Function(
Pointer<Utf8> key, Int8 value);
typedef PreferenceSetBoolean = int Function(Pointer<Utf8> key, int value);

// int preference_get_boolean (const char *key, bool *value)
typedef preference_get_boolean_native_t = Int32 Function(
typedef PreferenceGetBooleanNative = Int32 Function(
Pointer<Utf8> key, Pointer<Int8> value);
typedef PreferenceGetBoolean = int Function(
Pointer<Utf8> key, Pointer<Int8> value);

// int preference_remove (const char *key)
typedef preference_remove_native_t = Int32 Function(Pointer<Utf8> key);
typedef PreferenceRemoveNative = Int32 Function(Pointer<Utf8> key);
typedef PreferenceRemove = int Function(Pointer<Utf8> key);

// int preference_remove_all (void)
typedef preference_remove_all_native_t = Int32 Function();
typedef PreferenceRemoveAllNative = Int32 Function();
typedef PreferenceRemoveAll = int Function();

// typedef bool(* preference_item_cb )(const char *key, void *user_data)
typedef preference_item_cb_native_t = Int8 Function(
typedef PreferenceItemCallbackNative = Int8 Function(
Pointer<Utf8> key, Pointer<Void> userData);

// int preference_foreach_item (preference_item_cb callback, void *user_data)
typedef preference_foreach_item_native_t = Int32 Function(
Pointer<NativeFunction<preference_item_cb_native_t>> callback,
typedef PreferenceForeachItemNative = Int32 Function(
Pointer<NativeFunction<PreferenceItemCallbackNative>> callback,
Pointer<Void> userData);
typedef PreferenceForeachItem = int Function(
Pointer<NativeFunction<preference_item_cb_native_t>> callback,
Pointer<NativeFunction<PreferenceItemCallbackNative>> callback,
Pointer<Void> userData);
3 changes: 1 addition & 2 deletions packages/shared_preferences/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: shared_preferences_tizen
description: Tizen implementation of the shared_preferences plugin
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/shared_preferences
version: 2.0.1
version: 2.0.2

flutter:
plugin:
platforms:
tizen:
dartPluginClass: SharedPreferencesPlugin
fileName: shared_preferences_tizen.dart

dependencies:
ffi: ^1.1.2
Expand Down

0 comments on commit c9f7432

Please sign in to comment.