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

[shared_preferences] Merge iOS and macOS implementations #6920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ packages/ios_platform_images/ios/** @jmagman
packages/local_auth/local_auth_ios/** @hellohuanlin
packages/path_provider/path_provider_ios/** @jmagman
packages/quick_actions/quick_actions_ios/** @hellohuanlin
packages/shared_preferences/shared_preferences_ios/** @cyanglaz
packages/shared_preferences/shared_preferences_foundation/** @cyanglaz
packages/url_launcher/url_launcher_ios/** @jmagman
packages/video_player/video_player_avfoundation/** @hellohuanlin
packages/webview_flutter/webview_flutter_wkwebview/** @cyanglaz
Expand All @@ -65,7 +65,6 @@ packages/url_launcher/url_launcher_linux/** @cbracken
# - macOS
packages/file_selector/file_selector_macos/** @cbracken
packages/path_provider/path_provider_macos/** @cbracken
packages/shared_preferences/shared_preferences_macos/** @cbracken
packages/url_launcher/url_launcher_macos/** @cbracken

# - Windows
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 2.1.0

* Renames the package previously published as
[`shared_preferences_macos`](https://pub.dev/packages/shared_preferences_macos)
* Adds iOS support.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# shared\_preferences\_ios
# shared\_preferences\_foundation

The iOS implementation of [`shared_preferences`][1].
The iOS and macOS implementation of [`shared_preferences`][1].

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import FlutterMacOS
import Foundation

#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#endif
Comment on lines +7 to +11
Copy link
Member

Choose a reason for hiding this comment

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

This would be avoided by flutter/flutter#70413

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. This is something I could try to make time for in 2023 maybe?

Copy link
Member

Choose a reason for hiding this comment

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

It would be really great to unify these frameworks and APIs more, as you know 🙂


public class SharedPreferencesPlugin: NSObject, FlutterPlugin, UserDefaultsApi {
public static func register(with registrar: FlutterPluginRegistrar) {
let instance = SharedPreferencesPlugin()
UserDefaultsApiSetup.setUp(binaryMessenger: registrar.messenger, api: instance)
// Workaround for https://github.com/flutter/flutter/issues/118103.
#if os(iOS)
let messenger = registrar.messenger()
#else
let messenger = registrar.messenger
#endif
UserDefaultsApiSetup.setUp(binaryMessenger: messenger, api: instance)
}

func getAll() -> [String? : Any?] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import FlutterMacOS
import XCTest
@testable import shared_preferences_macos

#if os(iOS)
import Flutter
#elseif os(macOS)
import FlutterMacOS
#endif

@testable import shared_preferences_foundation

class RunnerTests: XCTestCase {
func testSetAndGet() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'shared_preferences_macos'
s.name = 'shared_preferences_foundation'
s.version = '0.0.1'
s.summary = 'macOS implementation of the shared_preferences plugin.'
s.summary = 'iOS and macOS implementation of the shared_preferences plugin.'
s.description = <<-DESC
Wraps NSUserDefaults, providing a persistent store for simple key-value pairs.
DESC
s.homepage = 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_macos'
s.homepage = 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_foundation'
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Flutter Team' => '[email protected]' }
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_macos' }
s.source = { :http => 'https://github.com/flutter/plugins/tree/main/packages/shared_preferences/shared_preferences_foundation' }
s.source_files = 'Classes/**/*'
s.dependency 'FlutterMacOS'

s.platform = :osx, '10.11'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'

end

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
Expand All @@ -31,9 +32,6 @@
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:shared_preferences_platform_interface/shared_preferences_platfor
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('SharedPreferencesIos', () {
group('SharedPreferencesFoundation', () {
const Map<String, Object> kTestValues = <String, Object>{
'flutter.String': 'hello world',
'flutter.bool': true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/dgph
*.mode1v3
*.mode2v3
*.moved-aside
Expand All @@ -18,6 +19,7 @@ Flutter/App.framework
Flutter/Flutter.framework
Flutter/Flutter.podspec
Flutter/Generated.xcconfig
Flutter/ephemeral/
Flutter/app.flx
Flutter/app.zip
Flutter/flutter_assets/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -28,6 +28,9 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe
flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
Expand Down
Loading