unleash_proxy_client_flutter 1.5.1 copy "unleash_proxy_client_flutter: ^1.5.1" to clipboard
unleash_proxy_client_flutter: ^1.5.1 copied to clipboard

A Flutter/Dart client that can be used together with the unleash-proxy, Unleash Edge and Unleash Frontend API.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:unleash_proxy_client_flutter/unleash_proxy_client_flutter.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Unleash Integration Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Unleash Integration Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  bool _counterEnabled = false;


  @override
  void initState() {
    super.initState();
    var unleash = UnleashClient(
        url: Uri.parse('https://sandbox.getunleash.io/enterprise/api/frontend'),
        clientKey: 'SDKIntegration:development.f0474f4a37e60794ee8fb00a4c112de58befde962af6d5055b383ea3',
        refreshInterval: 30,
        appName: 'example-flutter-app');
    void updateCounterEnabled(_) {
      final counterEnabled = unleash.isEnabled('counter');
      setState(() {
        _counterEnabled = counterEnabled;
      });
    }
    unleash.on('ready', updateCounterEnabled);
    unleash.on('update', updateCounterEnabled);
    unleash.start();
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('${widget.title} (counter is ${_counterEnabled ? 'enabled' : 'disabled'})'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _counterEnabled ? _incrementCounter : null,
        tooltip: 'Increment',
        child: _counterEnabled ? const Icon(Icons.add) : const Icon(Icons.disabled_by_default),
      ),
    );
  }
}
9
likes
130
pub points
89%
popularity

Publisher

verified publishergetunleash.io

A Flutter/Dart client that can be used together with the unleash-proxy, Unleash Edge and Unleash Frontend API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

events_emitter, flutter, http, shared_preferences, uuid

More

Packages that depend on unleash_proxy_client_flutter