Skip to content

Commit

Permalink
Support for all flags
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-paraense committed Feb 10, 2020
1 parent 96afd7e commit 732a533
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 0.3.0

* Adding all flags support.

## 0.2.0

* Adding real-time updates support.
* Adding real-time updates support for feature flags.

## 0.1.7

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.oakam.launchdarkly_flutter'
version '0.2.0'
version '0.3.0'

buildscript {
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String flagKey = call.argument("flagKey");
String fallback = call.argument("fallback");
result.success(ldClient.stringVariation(flagKey,fallback));
} else if (call.method.equals("registerFeatureFlagListener")) {
} else if (call.method.equals("allFlags")) {
result.success(ldClient.allFlags());
}else if (call.method.equals("registerFeatureFlagListener")) {

String flagKey = call.argument("flagKey");

Expand Down
28 changes: 28 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
bool _shouldShow = false;
bool _listenerRegistered = false;
Map<String, dynamic> _allFlags = {};
LaunchdarklyFlutter launchdarklyFlutter;

String mobileKey = 'YOUR_MOBILE_KEY';
Expand Down Expand Up @@ -86,6 +87,14 @@ class _MyAppState extends State<MyApp> {
? 'Unregister listener'
: 'Register listener'),
),
SizedBox(height: 30.0,),
RaisedButton(
onPressed: () async {
_verifyAllFlags();
},
child: Text('Verify all flags'),
),
Text('All flags: $_allFlags\n'),
],
),
),
Expand All @@ -111,4 +120,23 @@ class _MyAppState extends State<MyApp> {
_shouldShow = shouldShow;
});
}

void _verifyAllFlags() async {
Map<String, dynamic> allFlags;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
allFlags = await launchdarklyFlutter.allFlags();
} on PlatformException {
allFlags = {};
}

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;

setState(() {
_allFlags = allFlags;
});
}
}
10 changes: 8 additions & 2 deletions ios/Classes/SwiftLaunchdarklyFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import LaunchDarkly
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as! [String:Any]
let arguments = call.arguments as? [String:Any] ?? [:]

if (call.method == "init") {

Expand Down Expand Up @@ -76,7 +76,13 @@ import LaunchDarkly

result(LDClient.shared.variation(forKey: flagKey, fallback: fallback) as String)

} else if(call.method == "registerFeatureFlagListener") {
} else if(call.method == "allFlags") {

let allFlags = LDClient.shared.allFlagValues ?? [:]

result(allFlags)

}else if(call.method == "registerFeatureFlagListener") {

let flagKey = arguments["flagKey"] as? String ?? ""

Expand Down
2 changes: 1 addition & 1 deletion ios/launchdarkly_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'launchdarkly_flutter'
s.version = '0.2.0'
s.version = '0.3.0'
s.summary = 'A Flutter LaunchDarkly SDK.'
s.description = <<-DESC
This is an unofficial LaunchDarkly SDK for Flutter, for anyone willing to use LaunchDarkly in a Flutter app.
Expand Down
7 changes: 7 additions & 0 deletions lib/launchdarkly_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,11 @@ class LaunchdarklyFlutter {
return await _channel.invokeMethod(
'unregisterFeatureFlagListener', <String, dynamic>{'flagKey': flagKey});
}

/// Returns a map of all feature flags for the current user. No events are sent to LaunchDarkly.
Future<Map<String, dynamic>> allFlags() async {
Map<String, dynamic> allFlags =
Map<String, dynamic>.from(await _channel.invokeMethod('allFlags'));
return allFlags;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: launchdarkly_flutter
description: This is an unofficial LaunchDarkly SDK for Flutter, for anyone willing to use LaunchDarkly in a Flutter app.
version: 0.2.0
version: 0.3.0
homepage: https://github.com/andre-paraense/launchdarkly_flutter
issue_tracker: https://github.com/andre-paraense/launchdarkly_flutter/issues

Expand Down
13 changes: 13 additions & 0 deletions test/launchdarkly_flutter_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:launchdarkly_flutter/launchdarkly_flutter.dart';
Expand Down Expand Up @@ -47,6 +49,11 @@ void main() {
return true;
}

if (methodCall.method == 'allFlags') {
Map<String, dynamic> response = jsonDecode('{"flagKey":true}');
return response;
}

return launchdarklyFlutter.handlerMethodCalls(methodCall);
});
});
Expand Down Expand Up @@ -197,4 +204,10 @@ void main() {
'callbackRegisterFeatureFlagListener', arguments),
true);
});

test('allFlags', () async {
Map<String, dynamic> response = await launchdarklyFlutter.allFlags();

expect(response['flagKey'], true);
});
}

0 comments on commit 732a533

Please sign in to comment.