{"id":19149819,"url":"https://github.com/harness/ff-flutter-client-sdk","last_synced_at":"2025-05-07T04:44:47.449Z","repository":{"id":37952021,"uuid":"348434364","full_name":"harness/ff-flutter-client-sdk","owner":"harness","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-04T12:55:25.000Z","size":1785,"stargazers_count":3,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-07T04:44:41.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harness.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-16T17:25:18.000Z","updated_at":"2025-03-18T21:49:02.000Z","dependencies_parsed_at":"2025-04-19T15:50:53.275Z","dependency_job_id":"502946cb-dad0-4262-a414-18cd9a3899b7","html_url":"https://github.com/harness/ff-flutter-client-sdk","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-flutter-client-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-flutter-client-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-flutter-client-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-flutter-client-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harness","download_url":"https://codeload.github.com/harness/ff-flutter-client-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816520,"owners_count":21808702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T08:09:45.951Z","updated_at":"2025-05-07T04:44:47.428Z","avatar_url":"https://github.com/harness.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"Flutter SDK For Harness Feature Flags\n========================\n\n## Table of Contents\n**[Intro](#Intro)**\u003cbr\u003e\n**[Requirements](#Requirements)**\u003cbr\u003e\n**[Quickstart](#Quickstart)**\u003cbr\u003e\n**[Further Reading](docs/further_reading.md)**\u003cbr\u003e\n\n\n## Flutter SDK For Harness Feature Flags\nUse this README  to get started with our Feature Flags (FF) SDK for Flutter. This guide outlines the basics of getting started with the SDK and provides a full code sample for you to try out.\n\nThis sample doesn't include configuration options, for in depth steps and configuring the SDK, for example, disabling streaming or using our Relay Proxy, see the [Flutter SDK Reference](https://docs.harness.io/article/mmf7cu2owg-flutter-sdk-reference).\n\n![FeatureFlags](./docs/images/ff-gui.png)\n\n## Requirements\n\nTo use version 2 of the SDK, make sure you've:\n- Installed [Flutter SDK \u003e= 2.10.4](https://docs.flutter.dev/get-started/install)\n- Minimum Dart SDK is 2.12\n- For iOS Apps [Xcode](https://docs.flutter.dev/get-started/install/macos#install-xcode)\n- For Android Apps\u003cbr\u003e [Android Studio](https://developer.android.com/studio?gclid=CjwKCAjwp7eUBhBeEiwAZbHwkRqdhQkk6wroJeWGu0uGWjW9Ue3hFXc4SuB6lwYU4LOZiZ-MQ4p57BoCvF0QAvD_BwE\u0026gclsrc=aw.ds) or the [Android SDK](docs/dev_environment.md) for CLI only\u003cbr\u003e\n\nTo use version 1 of the SDK, make sure you've:\n- Installed [Flutter SDK \u003e= 2.10.4](https://docs.flutter.dev/get-started/install) \n- Minimum Dark SDK is 2.7\n- For iOS Apps [Xcode](https://docs.flutter.dev/get-started/install/macos#install-xcode)\n- For Android Apps\u003cbr\u003e [Android Studio](https://developer.android.com/studio?gclid=CjwKCAjwp7eUBhBeEiwAZbHwkRqdhQkk6wroJeWGu0uGWjW9Ue3hFXc4SuB6lwYU4LOZiZ-MQ4p57BoCvF0QAvD_BwE\u0026gclsrc=aw.ds) or the [Android SDK](docs/dev_environment.md) for CLI only\u003cbr\u003e\n\n\n\nYou can use Flutter doctor to verify you have the neccessary prerequisites\n```shell\nflutter doctor\n```\n\nTo follow along with our test code sample, make sure you've:\n- [Created a Feature Flag on the Harness Platform](https://docs.harness.io/article/1j7pdkqh7j-create-a-feature-flag).\n- [Created a [server/client] SDK key and made a copy of it](https://docs.harness.io/article/1j7pdkqh7j-create-a-feature-flag#step_3_create_an_sdk_key)\n\n## Install the SDK\n\n### Add the Dependency\nBegin by adding the Feature Flag Flutter SDK dependency to your pubspec.yaml file:\n\n\n```\nff_flutter_client_sdk: ^2.1.0\n```\n\n### Import Necessary Packages\nOnce you've added the dependency, import the necessary packages into your Dart files:\n\n```\nimport 'package:ff_flutter_client_sdk/CfClient.dart';  \nimport 'package:ff_flutter_client_sdk/CfConfiguration.dart';  \nimport 'package:ff_flutter_client_sdk/CfTarget.dart';\n```\n\n### Release mode for Android applications\nIn release mode, Flutter applies optimizations that can affect the behavior of native Android code, including code used by our Flutter Android plugin. \n\nPlease add the following rule to your ProGuard configuration to ensure proper functionality when running your Android app in release mode\n\n-keep class io.harness.cfsdk.** { *; } \n\n### SDK Installation for Flutter Web\nIf you're targeting a Flutter web application:\n\n1. Follow the steps mentioned above to set up the SDK in your project.\n\n2. In addition, embed our JavaScript SDK by adding the following script tag to the `\u003chead\u003e` section of your web page:\n```html\n  \u003cscript src=\"https://sdk.ff.harness.io/1.19.2/sdk.client-iife.js\"\u003e\u003c/script\u003e\n```\n\nThis installs our Feature Flags JavaScript SDK and makes it available to your application. Please ensure you regularly upgrade the\nJavaScript SDK version to get the latest updates. For the newest JavaScript SDK updates, monitor:\n\n* [JavaScript SDK GitHub Repo](https://github.com/harness/ff-javascript-client-sdk/releases)\n* [official Feature Flags Releases Page](https://developer.harness.io/release-notes/feature-flags)\n\n## Code Sample\nThe following is a complete code example that you can use to test the harnessappdemodarkmode Flag you created on the Harness Platform. When you run the code it will:\n1. Connect to the FF service.\n2. Report the value of the Flag every 10 seconds until the connection is closed. Every time the `harnessappdemodarkmode` Flag is toggled on or off on the Harness Platform, the updated value is reported.\n3. Close the SDK.\n\nTo use this sample, copy it into your project and enter your SDK key into the `FF_API_KEY` field.\n\n```Dart\n// @dart=2.12.0\nimport 'dart:async';\nimport 'package:flutter/material.dart';\nimport 'package:ff_flutter_client_sdk/CfClient.dart';\n\n// The SDK API Key to use for authentication.  Configure it when installing the app by setting FF_API_KEY\n// e.g..\nconst apiKey = String.fromEnvironment('FF_API_KEY', defaultValue: '');\n\n// The flag name\nconst flagName = String.fromEnvironment('FF_FLAG_NAME', defaultValue: 'harnessappdemodarkmode');\n\nvoid main() =\u003e runApp(MyApp());\n\n// A simple StatelessWidget that fetches the latest value from the FF Service.\n// Everytime it receives an update the value of the flag is updated.\nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(title: 'Harness Flutter SDK Getting Started', home: FlagState());\n  }\n}\n\nclass FlagState extends StatefulWidget {\n  @override\n  _FlagState createState() =\u003e _FlagState();\n}\n\nclass _FlagState extends State\u003cFlagState\u003e {\n  bool _flagValue = false;\n\n  @override\n  void initState() {\n    super.initState();\n\n    // Create Default Configuration for the SDK.  We can use this to disable streaming,\n    // change the URL the client connects to etc\n    var conf = CfConfigurationBuilder().build();\n\n    // Create a target (different targets can get different results based on rules.  This include a custom attribute 'location')\n    var target = CfTargetBuilder().setIdentifier(\"fluttersdk\").setName(\"FlutterSDK\").build();\n\n    // Init the default instance of the Feature Flag Client\n    CfClient.getInstance().initialize(apiKey, conf, target)\n        .then((value){\n      if (value.success) {\n        print(\"Successfully initialized client\");\n\n        // Evaluate flag and set initial state\n        CfClient.getInstance().boolVariation(flagName, false).then((value) {\n          print(\"$flagName: $value\");\n          setState(() {\n            _flagValue = value;\n          });\n        });\n\n        // Setup Event Handler\n        CfClient.getInstance().registerEventsListener((data, eventType) {\n          print(\"received event: ${eventType.toString()} with Data: ${data.toString()}\");\n          switch (eventType) {\n                case EventType.EVALUATION_CHANGE:\n                    String flag = (data as EvaluationResponse).flag;\n                    dynamic value = (data as EvaluationResponse).value;\n                    // If the change concerns the flag we care about, then update the state\n                    if ( flag == flagName ) {\n                        setState(() {\n                           _flagValue = value.toLowerCase() == 'true';\n                        });\n                    }\n                    break;\n          }\n        });\n      }\n    });\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        title: const Text('Harness Flutter SDK Getting Started'),\n      ),\n      body: Container(\n        child: Center(\n          child: new Text(\"${flagName} : ${_flagValue}\", style: TextStyle(fontSize: 25)),\n        ),\n      ),\n    );\n  }\n}\n```\n\nCertainly! Incorporating the recent details into the README section:\n\n---\n\n### Running the Getting Started Example\n\nFirst, provide your API key in the `.env` [file](examples/getting_started/.env) \n\nYou can then use [Android Studio](https://docs.flutter.dev/tools/android-studio) to run the [getting started example](examples/getting_started) \n\nYou can also run the [getting started example](examples/getting_started) using the Flutter CLI by following these steps:\n\n1. **Prerequisites**:\n    - Make sure Flutter is set up on your machine.\n    - Decide whether you're targeting an Android emulator, iOS simulator, or a web browser.\n\n2. **Setting Up and Choosing Your Target**:\n\n   **Verification**:\n    - To see available devices/emulators:\n      ```shell\n      flutter devices\n      ```\n    \n   The output will list your devices, for example:\n    ```plaintext\n    2 connected devices:\n    sdk gphone64 x86 64 (mobile) • emulator-5554                        • android-x64    • Android 12 (API 32) (emulator)\n    iPhone 13 (mobile)           • 425E99F8-702F-4E15-8BBE-B792BF15ED88 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)\n    ```\n   \n\n   **Android Emulator**:\n    - To start the Android emulator, use:\n      ```shell\n      $ANDROID_SDK/emulator/emulator @Pixel_4.4_API_32\n      ```\n      Replace `@Pixel_4.4_API_32` with your own emulator device ID.\n\n    - To run the Flutter app on your Android emulator:\n      ```shell\n      flutter run -d emulator-5554\n      ```\n\n   **iOS Simulator**:\n    - To open the iOS simulator:\n      ```shell\n      open -a simulator\n      ```\n    - To run the Flutter app on the iOS simulator:\n      ```shell\n      flutter run -d 425E99F8-702F-4E15-8BBE-B792BF15ED88\n      ```\n\n\n\n3. **Running the Example on Web**:\n\n   If targeting a web browser, use:\n    ```shell\n    flutter run -d chrome --hot\n    ```\n\n#### Build the project\nUsing the SDK API key, and a device ID from above you can build and install your app\non a emulator\n```shell\ncd examples/getting_started\nexport FF_API_KEY=\u003cyour api key\u003e\n\nflutter pub get\nflutter run --dart-define=FF_API_KEY=$FF_API_KEY -d \u003cdevice id\u003e\n```\n\nThe app should show the configured flags current value. As you toggle the flag in the Harrness UI you will see the value update.\n\u003cbr\u003e\u003cbr\u003e\n\n![Alt Text](docs/images/flutter.gif)\n\u003cbr\u003e\n\n## Additional Reading\n\nFor further examples and config options, see the [Flutter SDK Reference](https://docs.harness.io/article/mmf7cu2owg-flutter-sdk-reference) and the [test Flutter project](https://github.com/harness/ff-flutter-client-sdk/blob/main/examples/getting_started/lib/main.dart).\n\n[Further Reading](docs/further_reading.md)\u003cbr\u003e\n[Getting Started Example](examples/getting_started)\u003cbr\u003e\n[Advanced Example](https://github.com/drone/ff-flutter-client-sample)\n\nFor more information about Feature Flags, see our [Feature Flags documentation](https://docs.harness.io/article/0a2u2ppp8s-getting-started-with-feature-flags).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharness%2Fff-flutter-client-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharness%2Fff-flutter-client-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharness%2Fff-flutter-client-sdk/lists"}