launchdarkly_flutter 0.1.3 copy "launchdarkly_flutter: ^0.1.3" to clipboard
launchdarkly_flutter: ^0.1.3 copied to clipboard

discontinuedreplaced by: launchdarkly_flutter_client_sdk
outdated

This is an unofficial LaunchDarkly SDK for Flutter, for anyone willing to use LaunchDarkly in a Flutter app.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:launchdarkly_flutter/launchdarkly_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _shouldShow = false;
  LaunchdarklyFlutter launchdarklyFlutter;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.

    launchdarklyFlutter = LaunchdarklyFlutter();

    try {
      await launchdarklyFlutter.init('YOUR_MOBILE_KEY', 'USER_ID');
    } on PlatformException {}
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('LaunchDarkly Plugin'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Should show: $_shouldShow\n'),
              RaisedButton(
                onPressed: () async {
                  verifyFlag();
                },
                child: Text('Verify'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void verifyFlag() async {
    bool shouldShowButton;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      shouldShowButton =
          await launchdarklyFlutter.boolVariation('FLAG_KEY', false);
    } on PlatformException {
      shouldShowButton = false;
    }

    // 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(() {
      _shouldShow = shouldShowButton;
    });
  }
}
8
likes
0
pub points
15%
popularity

Publisher

verified publisheroakam.com

This is an unofficial LaunchDarkly SDK for Flutter, for anyone willing to use LaunchDarkly in a Flutter app.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on launchdarkly_flutter