Skip to content

Commit 0b12c25

Browse files
swift-kimbbrto21
andauthored
[shared_preferences] Add shared_preferences_tizen package (#5)
Co-authored-by: Boram Bae <[email protected]>
1 parent 2e11a38 commit 0b12c25

19 files changed

+674
-0
lines changed
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Initial release

packages/shared_preferences/LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
2+
Copyright (c) 2017 The Chromium Authors. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the names of the copyright holders nor the names of the
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/shared_preferences/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# shared_preferences_tizen
2+
3+
The Tizen implementation of [`shared_preferences`](https://github.com/flutter/plugins/tree/master/packages/shared_preferences).
4+
5+
## Usage
6+
7+
This package is not an _endorsed_ implementation of `shared_preferences`. Therefore, you have to include `shared_preferences_tizen` alongside `shared_preferences` as dependencies in your `pubspec.yaml` file.
8+
9+
```yaml
10+
dependencies:
11+
shared_preferences: ^0.5.12
12+
shared_preferences_tizen: ^1.0.0
13+
```
14+
15+
Then you can import `shared_preferences` in your Dart code:
16+
17+
```dart
18+
import 'package:shared_preferences/shared_preferences.dart';
19+
```
20+
21+
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences#usage.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# shared_preferences_tizen_example
2+
3+
Demonstrates how to use the shared_preferences_tizen plugin.
4+
5+
## Getting Started
6+
7+
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2019, the Chromium project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:shared_preferences/shared_preferences.dart';
8+
import 'package:integration_test/integration_test.dart';
9+
10+
void main() {
11+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
12+
13+
group('$SharedPreferences', () {
14+
const Map<String, dynamic> kTestValues = <String, dynamic>{
15+
'flutter.String': 'hello world',
16+
'flutter.bool': true,
17+
'flutter.int': 42,
18+
'flutter.double': 3.14159,
19+
'flutter.List': <String>['foo', 'bar'],
20+
};
21+
22+
const Map<String, dynamic> kTestValues2 = <String, dynamic>{
23+
'flutter.String': 'goodbye world',
24+
'flutter.bool': false,
25+
'flutter.int': 1337,
26+
'flutter.double': 2.71828,
27+
'flutter.List': <String>['baz', 'quox'],
28+
};
29+
30+
SharedPreferences preferences;
31+
32+
setUp(() async {
33+
preferences = await SharedPreferences.getInstance();
34+
});
35+
36+
tearDown(() {
37+
preferences.clear();
38+
});
39+
40+
test('reading', () async {
41+
expect(preferences.get('String'), isNull);
42+
expect(preferences.get('bool'), isNull);
43+
expect(preferences.get('int'), isNull);
44+
expect(preferences.get('double'), isNull);
45+
expect(preferences.get('List'), isNull);
46+
expect(preferences.getString('String'), isNull);
47+
expect(preferences.getBool('bool'), isNull);
48+
expect(preferences.getInt('int'), isNull);
49+
expect(preferences.getDouble('double'), isNull);
50+
expect(preferences.getStringList('List'), isNull);
51+
});
52+
53+
test('writing', () async {
54+
await Future.wait(<Future<bool>>[
55+
preferences.setString('String', kTestValues2['flutter.String']),
56+
preferences.setBool('bool', kTestValues2['flutter.bool']),
57+
preferences.setInt('int', kTestValues2['flutter.int']),
58+
preferences.setDouble('double', kTestValues2['flutter.double']),
59+
preferences.setStringList('List', kTestValues2['flutter.List'])
60+
]);
61+
expect(preferences.getString('String'), kTestValues2['flutter.String']);
62+
expect(preferences.getBool('bool'), kTestValues2['flutter.bool']);
63+
expect(preferences.getInt('int'), kTestValues2['flutter.int']);
64+
expect(preferences.getDouble('double'), kTestValues2['flutter.double']);
65+
expect(preferences.getStringList('List'), kTestValues2['flutter.List']);
66+
});
67+
68+
test('removing', () async {
69+
const String key = 'testKey';
70+
await preferences.setString(key, kTestValues['flutter.String']);
71+
await preferences.setBool(key, kTestValues['flutter.bool']);
72+
await preferences.setInt(key, kTestValues['flutter.int']);
73+
await preferences.setDouble(key, kTestValues['flutter.double']);
74+
await preferences.setStringList(key, kTestValues['flutter.List']);
75+
await preferences.remove(key);
76+
expect(preferences.get('testKey'), isNull);
77+
});
78+
79+
test('clearing', () async {
80+
await preferences.setString('String', kTestValues['flutter.String']);
81+
await preferences.setBool('bool', kTestValues['flutter.bool']);
82+
await preferences.setInt('int', kTestValues['flutter.int']);
83+
await preferences.setDouble('double', kTestValues['flutter.double']);
84+
await preferences.setStringList('List', kTestValues['flutter.List']);
85+
await preferences.clear();
86+
expect(preferences.getString('String'), null);
87+
expect(preferences.getBool('bool'), null);
88+
expect(preferences.getInt('int'), null);
89+
expect(preferences.getDouble('double'), null);
90+
expect(preferences.getStringList('List'), null);
91+
});
92+
});
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:async';
8+
9+
import 'package:flutter/material.dart';
10+
import 'package:shared_preferences/shared_preferences.dart';
11+
12+
void main() {
13+
runApp(MyApp());
14+
}
15+
16+
class MyApp extends StatelessWidget {
17+
@override
18+
Widget build(BuildContext context) {
19+
return MaterialApp(
20+
title: 'SharedPreferences Demo',
21+
home: SharedPreferencesDemo(),
22+
);
23+
}
24+
}
25+
26+
class SharedPreferencesDemo extends StatefulWidget {
27+
SharedPreferencesDemo({Key key}) : super(key: key);
28+
29+
@override
30+
SharedPreferencesDemoState createState() => SharedPreferencesDemoState();
31+
}
32+
33+
class SharedPreferencesDemoState extends State<SharedPreferencesDemo> {
34+
Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
35+
Future<int> _counter;
36+
37+
Future<void> _incrementCounter() async {
38+
final SharedPreferences prefs = await _prefs;
39+
final int counter = (prefs.getInt('counter') ?? 0) + 1;
40+
41+
setState(() {
42+
_counter = prefs.setInt("counter", counter).then((bool success) {
43+
return counter;
44+
});
45+
});
46+
}
47+
48+
@override
49+
void initState() {
50+
super.initState();
51+
_counter = _prefs.then((SharedPreferences prefs) {
52+
return (prefs.getInt('counter') ?? 0);
53+
});
54+
}
55+
56+
@override
57+
Widget build(BuildContext context) {
58+
return Scaffold(
59+
appBar: AppBar(
60+
title: const Text("SharedPreferences Demo"),
61+
),
62+
body: Center(
63+
child: FutureBuilder<int>(
64+
future: _counter,
65+
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
66+
switch (snapshot.connectionState) {
67+
case ConnectionState.waiting:
68+
return const CircularProgressIndicator();
69+
default:
70+
if (snapshot.hasError) {
71+
return Text('Error: ${snapshot.error}');
72+
} else {
73+
return Text(
74+
'Button tapped ${snapshot.data} time${snapshot.data == 1 ? '' : 's'}.\n\n'
75+
'This should persist across restarts.',
76+
);
77+
}
78+
}
79+
})),
80+
floatingActionButton: FloatingActionButton(
81+
onPressed: _incrementCounter,
82+
tooltip: 'Increment',
83+
child: const Icon(Icons.add),
84+
),
85+
);
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: shared_preferences_tizen_example
2+
description: Demonstrates how to use the shared_preferences_tizen plugin.
3+
publish_to: "none"
4+
5+
dependencies:
6+
flutter:
7+
sdk: flutter
8+
shared_preferences: ^0.5.12
9+
shared_preferences_tizen:
10+
path: ../
11+
12+
dev_dependencies:
13+
flutter_driver:
14+
sdk: flutter
15+
integration_test: ^0.9.2
16+
integration_test_tizen:
17+
path: ../../integration_test/
18+
pedantic: ^1.8.0
19+
20+
flutter:
21+
uses-material-design: true
22+
23+
environment:
24+
sdk: ">=2.0.0-dev.28.0 <3.0.0"
25+
flutter: ">=1.9.1+hotfix.2 <2.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import 'package:integration_test/integration_test_driver.dart';
2+
3+
Future<void> main() => integrationDriver();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
flutter/
2+
.vs/
3+
*.user
4+
bin/
5+
obj/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Tizen.Flutter.Embedding;
2+
3+
namespace Runner
4+
{
5+
public class App : FlutterApplication
6+
{
7+
protected override void OnCreate()
8+
{
9+
base.OnCreate();
10+
11+
GeneratedPluginRegistrant.RegisterPlugins(this);
12+
}
13+
14+
static void Main(string[] args)
15+
{
16+
var app = new App();
17+
app.Run(args);
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
5+
<add key="tizen.myget.org" value="https://tizen.myget.org/F/dotnet/api/v3/index.json" protocolVersion="3" />
6+
</packageSources>
7+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Tizen.NET.Sdk/1.1.5">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>tizen60</TargetFramework>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
9+
<DebugType>portable</DebugType>
10+
</PropertyGroup>
11+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
12+
<DebugType>none</DebugType>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Tizen.Flutter.Embedding" Version="$(FlutterEmbeddingVersion)" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<FlutterEphemeral Include="flutter\ephemeral\**\*" />
21+
<TizenTpkUserIncludeFiles Include="@(FlutterEphemeral)">
22+
<TizenTpkSubDir>%(RecursiveDir)</TizenTpkSubDir>
23+
</TizenTpkUserIncludeFiles>
24+
</ItemGroup>
25+
26+
</Project>
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="org.tizen.shared_preferences_tizen_example" version="1.0.0" api-version="5.5" xmlns="http://tizen.org/ns/packages">
3+
<profile name="common"/>
4+
<ui-application appid="org.tizen.shared_preferences_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="6" launch_mode="single">
5+
<label>shared_preferences_tizen_example</label>
6+
<icon>ic_launcher.png</icon>
7+
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true"/>
8+
</ui-application>
9+
<feature name="http://tizen.org/feature/screen.size.all"/>
10+
</manifest>

0 commit comments

Comments
 (0)