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

Commit be545f4

Browse files
authored
Upgrade shared_preferences to new plugin registration. (#31)
1 parent ebf2db2 commit be545f4

File tree

10 files changed

+68
-72
lines changed

10 files changed

+68
-72
lines changed

packages/shared-preferences/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.2.0] - 2017-05-10
2+
3+
* Upgrade to new plugin registration. (https://groups.google.com/forum/#!topic/flutter-dev/zba1Ynf2OKM)
4+
15
## [0.1.1] - 2017-05-09
26

37
* Upgrade Android SDK Build Tools to 25.0.3.

packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
package io.flutter.plugins.shared_preferences;
66

7+
import android.app.Activity;
78
import android.content.Context;
8-
import io.flutter.app.FlutterActivity;
99
import io.flutter.plugin.common.MethodChannel;
1010
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
11-
import io.flutter.plugin.common.MethodChannel.Result;
1211
import io.flutter.plugin.common.MethodCall;
13-
import io.flutter.view.FlutterView;
12+
import io.flutter.plugin.common.PluginRegistry;
1413
import java.util.HashMap;
1514
import java.util.HashSet;
1615
import java.util.List;
@@ -26,14 +25,15 @@ public class SharedPreferencesPlugin implements MethodCallHandler {
2625
private final android.content.SharedPreferences preferences;
2726
private final android.content.SharedPreferences.Editor editor;
2827

29-
public static SharedPreferencesPlugin register(FlutterActivity activity) {
30-
return new SharedPreferencesPlugin(activity);
28+
public static void registerWith(PluginRegistry.Registrar registrar) {
29+
MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
30+
SharedPreferencesPlugin instance = new SharedPreferencesPlugin(registrar.activity());
31+
channel.setMethodCallHandler(instance);
3132
}
3233

33-
private SharedPreferencesPlugin(FlutterActivity activity) {
34+
private SharedPreferencesPlugin(Activity activity) {
3435
preferences = activity.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
3536
editor = preferences.edit();
36-
new MethodChannel(activity.getFlutterView(), CHANNEL_NAME).setMethodCallHandler(this);
3737
}
3838

3939
// Filter preferences to only those set by the flutter app.

packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import android.os.Bundle;
44
import io.flutter.app.FlutterActivity;
5-
import io.flutter.plugins.PluginRegistry;
5+
import io.flutter.plugins.GeneratedPluginRegistrant;
66

77
public class MainActivity extends FlutterActivity {
8-
PluginRegistry pluginRegistry;
98

109
@Override
1110
protected void onCreate(Bundle savedInstanceState) {
1211
super.onCreate(savedInstanceState);
13-
pluginRegistry = new PluginRegistry();
14-
pluginRegistry.registerAll(this);
12+
GeneratedPluginRegistrant.registerWith(this);
1513
}
1614
}

packages/shared-preferences/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* PluginRegistry.m */; };
10+
2D92224B1EC342E7007564B0 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D92224A1EC342E7007564B0 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1212
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1313
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
14+
7484D44614CC7A0233629D78 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ABF3C366458B9090B9D1CC79 /* Pods_Runner.framework */; };
1415
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
1516
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1617
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
@@ -21,7 +22,6 @@
2122
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
2223
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
2324
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
24-
B1F3D14E8117A6C9F65810E0 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D558BB7489B1C82B42A9097 /* libPods-Runner.a */; };
2525
/* End PBXBuildFile section */
2626

2727
/* Begin PBXCopyFilesBuildPhase section */
@@ -40,11 +40,10 @@
4040
/* End PBXCopyFilesBuildPhase section */
4141

4242
/* Begin PBXFileReference section */
43-
1498D2321E8E86230040F4C2 /* PluginRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PluginRegistry.h; sourceTree = "<group>"; };
44-
1498D2331E8E89220040F4C2 /* PluginRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PluginRegistry.m; sourceTree = "<group>"; };
43+
2D9222491EC342E7007564B0 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
44+
2D92224A1EC342E7007564B0 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4545
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4646
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
47-
4D558BB7489B1C82B42A9097 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4847
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4948
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
5049
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -58,6 +57,7 @@
5857
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5958
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
6059
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
60+
ABF3C366458B9090B9D1CC79 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6161
/* End PBXFileReference section */
6262

6363
/* Begin PBXFrameworksBuildPhase section */
@@ -67,7 +67,7 @@
6767
files = (
6868
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
6969
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
70-
B1F3D14E8117A6C9F65810E0 /* libPods-Runner.a in Frameworks */,
70+
7484D44614CC7A0233629D78 /* Pods_Runner.framework in Frameworks */,
7171
);
7272
runOnlyForDeploymentPostprocessing = 0;
7373
};
@@ -117,15 +117,15 @@
117117
97C146F01CF9000F007C117D /* Runner */ = {
118118
isa = PBXGroup;
119119
children = (
120+
2D9222491EC342E7007564B0 /* GeneratedPluginRegistrant.h */,
121+
2D92224A1EC342E7007564B0 /* GeneratedPluginRegistrant.m */,
120122
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
121123
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
122124
97C146FA1CF9000F007C117D /* Main.storyboard */,
123125
97C146FD1CF9000F007C117D /* Assets.xcassets */,
124126
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
125127
97C147021CF9000F007C117D /* Info.plist */,
126128
97C146F11CF9000F007C117D /* Supporting Files */,
127-
1498D2321E8E86230040F4C2 /* PluginRegistry.h */,
128-
1498D2331E8E89220040F4C2 /* PluginRegistry.m */,
129129
);
130130
path = Runner;
131131
sourceTree = "<group>";
@@ -141,7 +141,7 @@
141141
CF3B75C9A7D2FA2A4C99F110 /* Frameworks */ = {
142142
isa = PBXGroup;
143143
children = (
144-
4D558BB7489B1C82B42A9097 /* libPods-Runner.a */,
144+
ABF3C366458B9090B9D1CC79 /* Pods_Runner.framework */,
145145
);
146146
name = Frameworks;
147147
sourceTree = "<group>";
@@ -292,7 +292,7 @@
292292
);
293293
runOnlyForDeploymentPostprocessing = 0;
294294
shellPath = /bin/sh;
295-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
295+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
296296
showEnvVarsInLog = 0;
297297
};
298298
/* End PBXShellScriptBuildPhase section */
@@ -304,7 +304,7 @@
304304
files = (
305305
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
306306
97C146F31CF9000F007C117D /* main.m in Sources */,
307-
1498D2341E8E89220040F4C2 /* PluginRegistry.m in Sources */,
307+
2D92224B1EC342E7007564B0 /* GeneratedPluginRegistrant.m in Sources */,
308308
);
309309
runOnlyForDeploymentPostprocessing = 0;
310310
};
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
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+
15
#include "AppDelegate.h"
2-
#include "PluginRegistry.h"
6+
#include "GeneratedPluginRegistrant.h"
37

4-
@implementation AppDelegate {
5-
PluginRegistry *plugins;
6-
}
8+
@implementation AppDelegate
79

810
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
9-
// Override point for customization after application launch.
10-
FlutterViewController *flutterController =
11-
(FlutterViewController *)self.window.rootViewController;
12-
plugins = [[PluginRegistry alloc] initWithController:flutterController];
13-
return YES;
14-
}
15-
16-
- (void)applicationWillResignActive:(UIApplication *)application {
17-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
18-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
19-
}
20-
21-
- (void)applicationDidEnterBackground:(UIApplication *)application {
22-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
23-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
24-
}
25-
26-
- (void)applicationWillEnterForeground:(UIApplication *)application {
27-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
28-
}
29-
30-
- (void)applicationDidBecomeActive:(UIApplication *)application {
31-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
32-
}
33-
34-
- (void)applicationWillTerminate:(UIApplication *)application {
35-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
11+
[GeneratedPluginRegistrant registerWithRegistry:self];
12+
return [super application:application didFinishLaunchingWithOptions:launchOptions];
3613
}
3714

3815
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#ifndef GeneratedPluginRegistrant_h
6+
#define GeneratedPluginRegistrant_h
7+
8+
#import <Flutter/Flutter.h>
9+
10+
#import "SharedPreferencesPlugin.h"
11+
12+
@interface GeneratedPluginRegistrant : NSObject
13+
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
14+
@end
15+
16+
#endif /* GeneratedPluginRegistrant_h */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#import "GeneratedPluginRegistrant.h"
6+
7+
@implementation GeneratedPluginRegistrant
8+
9+
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
10+
[SharedPreferencesPlugin registerWithRegistrar:[registry registrarForPlugin:@"SharedPreferencesPlugin"]];
11+
}
12+
13+
@end
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#import <Flutter/Flutter.h>
22

3-
@interface SharedPreferencesPlugin : NSObject
4-
- initWithController:(FlutterViewController *)controller;
3+
@interface SharedPreferencesPlugin : NSObject<FlutterPlugin>
54
@end

packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66

77
static NSString *const CHANNEL_NAME = @"plugins.flutter.io/shared_preferences";
88

9-
@implementation SharedPreferencesPlugin {
10-
FlutterMethodChannel *_channel;
11-
}
12-
13-
- (instancetype)initWithController:(FlutterViewController *)controller {
14-
if (self = [super init]) {
15-
_channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
16-
binaryMessenger:controller];
9+
@implementation SharedPreferencesPlugin
1710

18-
[_channel setMethodCallHandler:^(FlutterMethodCall *call,
11+
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
12+
FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME
13+
binaryMessenger:registrar.messenger];
14+
[channel setMethodCallHandler:^(FlutterMethodCall *call,
1915
FlutterResult result) {
2016
NSString *method = [call method];
2117
NSDictionary *arguments = [call arguments];
@@ -64,13 +60,6 @@ - (instancetype)initWithController:(FlutterViewController *)controller {
6460
result(FlutterMethodNotImplemented);
6561
}
6662
}];
67-
}
68-
return self;
69-
}
70-
71-
- (void)dealloc {
72-
[_channel setMethodCallHandler:nil];
73-
_channel = nil;
7463
}
7564

7665
#pragma mark - Private

packages/shared-preferences/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: shared_preferences
22

3-
version: 0.1.1
3+
version: 0.2.0
44
description: A Flutter plugin for reading and writing simple key-value pairs
55
author: Flutter Team <[email protected]>
66
homepage: https://github.com/flutter/plugins

0 commit comments

Comments
 (0)