Skip to content

Commit

Permalink
[feature]: add removeItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmadre committed Dec 3, 2020
1 parent 8300410 commit 2cd8caf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ios/Classes/SwiftFlutterWidgetkitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,30 @@ public class SwiftFlutterWidgetkitPlugin: NSObject, FlutterPlugin {

result(nil);
return;
} else if(call.method == "removeItem") {
if let args = call.arguments as? [String: Any],
let appGroup = args["appGroup"] as? String,
let key = args["key"] as? String {

var sharedDefaults: UserDefaults? = nil

if(appGroup != "") {
sharedDefaults = UserDefaults.init(suiteName: appGroup)
}

if(sharedDefaults == nil) {
result(nil)
return
}

sharedDefaults?.removeObject(forKey: key)

result(true)
return
}
}

result(FlutterMethodNotImplemented);
}
}

4 changes: 4 additions & 0 deletions lib/flutter_widgetkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ class WidgetKit {
static dynamic setItem(String key, dynamic value, String appGroup) async {
return await _channel.invokeMethod('setItem', <String, dynamic>{'key': key, 'value': value, 'appGroup': appGroup});
}

static Future<bool> removeItem(String key, String appGroup) async {
return await _channel.invokeMethod('removeItem', <String, dynamic>{'key': key, 'appGroup': appGroup});
}
}

0 comments on commit 2cd8caf

Please sign in to comment.