Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[shared_preferences] Add shared_preferences_windows #2988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d4a2904
Remove files
franciscojma86 Apr 9, 2020
230600c
Use path
franciscojma86 Apr 9, 2020
2f8e905
Update comments
franciscojma86 Apr 9, 2020
1a99a1a
Format
franciscojma86 Apr 9, 2020
1eb343d
Remove create
franciscojma86 Apr 9, 2020
8f2881c
fix
franciscojma86 Apr 9, 2020
946cc68
Address messages
franciscojma86 Apr 10, 2020
4ae2926
License
franciscojma86 Apr 15, 2020
79a4f29
Merge branch 'master' into shared
stuartmorgan-g Sep 1, 2020
1da5569
Minor fixes/updates
stuartmorgan-g Sep 1, 2020
de8ff2e
Revert everything outside of shared_preferences_windows
stuartmorgan-g Sep 1, 2020
8c82dc3
Make the example self-contained, following the model of Linux
stuartmorgan-g Sep 1, 2020
ec4e45d
Merge branch 'master' into shared-preferences-windows
stuartmorgan-g Sep 2, 2020
351244a
Update file dependency to resolve analyzer issue
stuartmorgan-g Sep 2, 2020
48f0cfb
Fix example test to be self-contained as well, rather than a copy of …
stuartmorgan-g Sep 2, 2020
dc7dbd3
Format
stuartmorgan-g Sep 2, 2020
416694a
Fix tests on non-Windows platforms
stuartmorgan-g Sep 2, 2020
5f3b240
Add a note not to land this version; the storage path doesn't match p…
stuartmorgan-g Sep 2, 2020
af2c1ad
Rework on top of path_provider_windows; initial verison
stuartmorgan-g Sep 4, 2020
54be015
Merge remote-tracking branch 'upstream/master' into shared-preference…
stuartmorgan-g Sep 4, 2020
0ea3b4d
Remove a TODO; this solution is a reasonable one
stuartmorgan-g Sep 16, 2020
9b53f83
Merge branch 'master' into shared-preferences-windows
stuartmorgan-g Sep 18, 2020
7f1a10d
Require path_provider_windows 0.0.2
stuartmorgan-g Sep 18, 2020
9d2f1d4
Update fake path provider
stuartmorgan-g Sep 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/shared_preferences/shared_preferences_windows/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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 and should not be manually edited.

version:
revision: df90bb5fd64e2066594151b9e311d45cd687a80c
channel: master

project_type: plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* Initial release to support shared_preferences on Windows.
27 changes: 27 additions & 0 deletions packages/shared_preferences/shared_preferences_windows/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 changes: 23 additions & 0 deletions packages/shared_preferences/shared_preferences_windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# shared_preferences_windows

The Windows implementation of [`shared_preferences`][1].

## Usage

### Import the package

This package has been endorsed, meaning that you only need to add `shared_preferences`
as a dependency in your `pubspec.yaml`. It will be automatically included in your app
when you depend on `package:shared_preferences`.

This is what the above means to your `pubspec.yaml`:

```yaml
...
dependencies:
...
shared_preferences: ^0.5.7
...
```

[1]: ../
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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 and should not be manually edited.

version:
revision: df90bb5fd64e2066594151b9e311d45cd687a80c
channel: master

project_type: app
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# shared_preferences_windows_example

Demonstrates how to use the shared_preferences_windows plugin.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:shared_preferences_windows/shared_preferences_windows.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SharedPreferences Demo',
home: SharedPreferencesDemo(),
);
}
}

class SharedPreferencesDemo extends StatefulWidget {
SharedPreferencesDemo({Key key}) : super(key: key);

@override
SharedPreferencesDemoState createState() => SharedPreferencesDemoState();
}

class SharedPreferencesDemoState extends State<SharedPreferencesDemo> {
final prefs = SharedPreferencesWindows.instance;
Future<int> _counter;

Future<void> _incrementCounter() async {
final values = await prefs.getAll();
final int counter = (values['counter'] as int ?? 0) + 1;

setState(() {
_counter = prefs.setValue(null, "counter", counter).then((bool success) {
return counter;
});
});
}

@override
void initState() {
super.initState();
_counter = prefs.getAll().then((Map<String, Object> values) {
return (values['counter'] ?? 0);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("SharedPreferences Demo"),
),
body: Center(
child: FutureBuilder<int>(
future: _counter,
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return const CircularProgressIndicator();
default:
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return Text(
'Button tapped ${snapshot.data} time${snapshot.data == 1 ? '' : 's'}.\n\n'
'This should persist across restarts.',
);
}
}
})),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: shared_preferences_windows_example
description: Demonstrates how to use the shared_preferences_windows plugin.

environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
shared_preferences_windows: ^0.0.1

dependency_overrides:
shared_preferences_windows:
path: ../

dev_dependencies:
flutter_driver:
sdk: flutter
test: any
e2e: ^0.2.0
pedantic: ^1.8.0

flutter:
uses-material-design: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences_windows/shared_preferences_windows.dart';
import 'package:e2e/e2e.dart';

void main() {
E2EWidgetsFlutterBinding.ensureInitialized();

group('SharedPreferencesWindows', () {
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 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'],
};

SharedPreferencesWindows preferences;

setUp(() async {
preferences = SharedPreferencesWindows.instance;
});

tearDown(() {
preferences.clear();
});

test('reading', () async {
final Map<String, Object> values = await preferences.getAll();
expect(values['String'], isNull);
expect(values['bool'], isNull);
expect(values['int'], isNull);
expect(values['double'], isNull);
expect(values['List'], isNull);
});

test('writing', () async {
await Future.wait(<Future<bool>>[
preferences.setValue(
'String', 'String', kTestValues2['flutter.String']),
preferences.setValue('Bool', 'bool', kTestValues2['flutter.bool']),
preferences.setValue('Int', 'int', kTestValues2['flutter.int']),
preferences.setValue(
'Double', 'double', kTestValues2['flutter.double']),
preferences.setValue('StringList', 'List', kTestValues2['flutter.List'])
]);
final Map<String, Object> values = await preferences.getAll();
expect(values['String'], kTestValues2['flutter.String']);
expect(values['bool'], kTestValues2['flutter.bool']);
expect(values['int'], kTestValues2['flutter.int']);
expect(values['double'], kTestValues2['flutter.double']);
expect(values['List'], kTestValues2['flutter.List']);
});

test('removing', () async {
const String key = 'testKey';
await preferences.setValue('String', key, kTestValues['flutter.String']);
await preferences.setValue('Bool', key, kTestValues['flutter.bool']);
await preferences.setValue('Int', key, kTestValues['flutter.int']);
await preferences.setValue('Double', key, kTestValues['flutter.double']);
await preferences.setValue(
'StringList', key, kTestValues['flutter.List']);
await preferences.remove(key);
final Map<String, Object> values = await preferences.getAll();
expect(values[key], isNull);
});

test('clearing', () async {
await preferences.setValue(
'String', 'String', kTestValues['flutter.String']);
await preferences.setValue('Bool', 'bool', kTestValues['flutter.bool']);
await preferences.setValue('Int', 'int', kTestValues['flutter.int']);
await preferences.setValue(
'Double', 'double', kTestValues['flutter.double']);
await preferences.setValue(
'StringList', 'List', kTestValues['flutter.List']);
await preferences.clear();
final Map<String, Object> values = await preferences.getAll();
expect(values['String'], null);
expect(values['bool'], null);
expect(values['int'], null);
expect(values['double'], null);
expect(values['List'], null);
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'package:flutter_driver/flutter_driver.dart';

Future<void> main() async {
final FlutterDriver driver = await FlutterDriver.connect();
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
await driver.close();
exit(result == 'pass' ? 0 : 1);
}
Loading