Skip to content

Commit

Permalink
implement getAllKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
nkmrh committed Nov 25, 2024
1 parent 7d64ef8 commit 1451791
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions example/lib/variables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ class _VariablesState extends State<VariablesScreen> {
Variables.fetch().then((value) async {
print("variables fetch completed!");
await checkVariables();
List allKeys = await Variables.getAllKeys();
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Fetch Succeeded. Keys:"),
content: Text(allKeys.join(',')),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text("OK")
),
],
);
}
);
});
},
child: Text("Fetch Variables"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public void run() {
Variables.trackOpen(variables, values);
result.success(null);
break;
case "getAllKeys":
result.success(Variables.getAllKeys());
break;
case "clearCache":
key = call.argument("key");
if (key == null) {
Expand Down
2 changes: 2 additions & 0 deletions karte_variables/ios/Classes/SwiftKarteVariablesPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class SwiftKarteVariablesPlugin: NSObject, FlutterPlugin {
let values = convertValues(arguments["values"])
Tracker.trackClick(variables: variables, values: values)
result(nil)
case "getAllKeys":
result(Variables.getAllKeys())
case "clearCache":
let key = arguments["key"] as? String ?? ""
Variables.clearCache(forKey: key)
Expand Down
10 changes: 10 additions & 0 deletions karte_variables/lib/karte_variables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ class Variables {
'Variables_trackClick', {"variableNames": names, "values": normalize(values)});
}

/// 全ての設定値のキーの一覧を取得します。
/// なお事前に `Variables.fetch()` を呼び出しておく必要があります。
static Future<List<String>> getAllKeys() async {
final result = await _channel.invokeMethod('Variables_getAllKeys');
if (result == null) {
return [];
}
return result.whereType<String>().toList();
}

/// 指定した設定値のキーのキャッシュを削除します。
static void clearCache(String key) async {
await _channel.invokeMethod('Variables_clearCache', {"key": key});
Expand Down

0 comments on commit 1451791

Please sign in to comment.