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

[shared_preferences] Adds support for Windows #2631

Closed
wants to merge 10 commits into from

Conversation

franciscojma86
Copy link
Contributor

@franciscojma86 franciscojma86 commented Apr 3, 2020

Description

Dart implementation of the shared_preferences plugin using ffi for Windows.

Related Issues

flutter/flutter#41719

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy].
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the [CLA].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@franciscojma86 franciscojma86 changed the title dShared [shared_preferences] Adds support for Windows Apr 4, 2020
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a quick skim of the Dart code; not a full review.

Capturing from offline discussion:

  • We shouldn't check in the Windows example folder, since it isn't stable. (Instead, CI should flutter create it on demand, so it's always using the current template iteration.)
  • flutter create . makes a much of changes to older ios/ and android/ directories; all those changes should be removed from the PR.

@franciscojma86 franciscojma86 marked this pull request as ready for review April 9, 2020 17:56
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good. There are a couple of questions we'll need to get input on, but I think it's really close.

static SharedPreferencesStorePlatform get _store =>
SharedPreferencesStorePlatform.instance;
static SharedPreferencesStorePlatform get _store {
if (LocalPlatform().isWindows) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that the registration of the default implementation is in the platform interface rather than this layer; this override has the unfortunate effect that setting a different instance explicitly (e.g., the in-memory implementation, or an unofficial alternate version) won't work on Windows.

I wonder if we should temporarily add a static property to disable this, so that in those cases people can get the dynamic behavior with, e.g., SharedPreferencesStorePlatform.disablePlatformOverride = true; before calling getInstance(). Removing it later when we don't need it would technically be a breaking change, but it would be a very easy one for people to deal with (just remove the line of code). @amirh, thoughts?

@@ -0,0 +1,27 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does flutter/plugins not use an identical license everywhere like flutter/engine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This license is the same as the one in shared_preferences, other than the year. Is that what you are referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically I was wondering if we are using a set year. flutter/engine does that, to avoid having a ton of license variations (which adds size to Flutter applications, since they include all the licenses).

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either have a license, or remove the file; it looks like both have been done. I'm not sure if one or the other is the preferred practice going forward so someone who knows should weigh in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the license from the front-end package

@franciscojma86
Copy link
Contributor Author

All comments have been addressed. Now waiting on plugin_tools and Cirrus CI to be updated.
plugin_tools PR: https://github.com/flutter/plugin_tools/pull/95

Also waiting on @amirh comments for the class registration.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some license questions left from me.

@@ -0,0 +1,27 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically I was wondering if we are using a set year. flutter/engine does that, to avoid having a ton of license variations (which adds size to Flutter applications, since they include all the licenses).

@franciscojma86
Copy link
Contributor Author

I changed the licenses to 2017 to match the rest of the repo. I have seen licenses with 2020 and 2019 in other packages, so I'm not really sure what's the policy. @amirh or @collinjackson might know?

@GroovinChip
Copy link

GroovinChip commented May 1, 2020

https://github.com/flutter/plugin_tools/pull/95 got merged, is anything else standing in the way of this PR being merged? I'm really excited for this to be official (I'm using it as a local path dependency and its great)

@stuartmorgan
Copy link
Contributor

Filed flutter/flutter#56143 to track what's still blocking this PR.

@skyred
Copy link

skyred commented Jul 7, 2020

Can someone please provide instructions on how to use/test this PR with your app? I imagine add a specific reference/patch to this MR in pubspec.yaml

@liudonghua123
Copy link

I hope this pr would be merged soon. 😄

@skyred
Copy link

skyred commented Aug 15, 2020

I tried to use the PR, by specifying below in pubspec.yaml

  shared_preferences:
    git:
      url: git@github.com:franciscojma86/plugins.git
      path: ./packages/shared_preferences/shared_preferences/
      ref: shared

But, got this error:

Error on line 34, column 11: Invalid description in the "shared_preferences" pubspec on the "shared_preferences_windows" dependency: "../shared_preferences_windows" is a relative path, but this isn't a local pubspec.

   ╷

34 │     path: ../shared_preferences_windows

   │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   ╵
pub get failed (65;    ╵)
exit code 65

Haven't found a solution yet, can someone please help?

@skyred
Copy link

skyred commented Aug 16, 2020

I had use this to make it working:

Step 1: git clone --branch shared git@github.com:franciscojma86/plugins.git --depth 1

Step 2: Update pubspec.yaml

dependencies:
  shared_preferences: '>=0.5.8 <2.0.0'
dependency_overrides:
  shared_preferences:
    path: ../plugins/packages/shared_preferences/shared_preferences/

Anyway, the functionality works in this PR.

@gerryhigh
Copy link
Contributor

gerryhigh commented Sep 13, 2020

Getting weird issue with isLinux and isWindows not defined--see below

I had use this to make it working:

Step 1: git clone --branch shared git@github.com:franciscojma86/plugins.git --depth 1

Step 2: Update pubspec.yaml

dependencies:
  shared_preferences: '>=0.5.8 <2.0.0'
dependency_overrides:
  shared_preferences:
    path: ../plugins/packages/shared_preferences/shared_preferences/

Anyway, the functionality works in this PR.

I tried this but get an issue when trying to run it in my app:

/plugins/packages/shared_preferences/shared_preferences/lib/shared_preferences.dart(38,22): error G3824A48C: Getter not found: 'isLinux'.
/plugins/packages/shared_preferences/shared_preferences/lib/shared_preferences.dart(40,29): error G3824A48C: Getter not found: 'isWindows'

Flutter Doctor:
[✓] Flutter (Channel master, 1.22.0-10.0.pre.153, on Microsoft Windows [Version 10.0.19041.508], locale en-US)
• Flutter version 1.22.0-10.0.pre.153 at c:...
• Framework revision 2e64365 (2 days ago), 2020-09-11 23:07:03 -0400
• Engine revision 16b900b63e
• Dart version 2.10.0 (build 2.10.0-117.0.dev)
[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.2)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.7.30413.136
• Windows 10 SDK version 10.0.18362.0
[✓] Connected device (1 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.508]

@stuartmorgan
Copy link
Contributor

Closing as obsolete. Most of the implementation landed in #2988, it will be published when #3058 lands, and then #3059 will add the endorsement.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
9 participants