feature_core 1.2.0 copy "feature_core: ^1.2.0" to clipboard
feature_core: ^1.2.0 copied to clipboard

Dart package for flexible retrieving and managing feature flags.

example/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:math';

import 'package:feature_core/feature_core.dart';
import 'package:logging/logging.dart';

class SomeDependency {
  final _rnd = Random();

  Future<String> getFeatures() async {
    final feature2Value = _rnd.nextInt(20);
    final feature1Value = feature2Value > 10;

    return '[{"key": "feature1", "value": "$feature1Value"},{"key": "feature2", "value": $feature2Value}]';
  }
}

class TestFeatureProvider extends FeaturesProvider {
  final SomeDependency dependency;

  TestFeatureProvider({
    required this.dependency,
  }) : super(
          name: 'Test provider',
          key: 'test_provider',
          needUpdater: true,
        ) {
    Timer.periodic(const Duration(seconds: 4), (timer) {
      requestPullFeatures();
    });
  }

  @override
  Future<Iterable<FeatureAbstract>> pullFeatures() async {
    final json = jsonDecode(await dependency.getFeatures()) as List<dynamic>;

    final features = json.map(
      (e) => FeatureGeneric(
        key: e['key'],
        value: e['value'],
      ),
    );

    return features;
  }
}

void main() {
  Logger.root.onRecord.listen((event) {
    print(event);
  });

  FeaturesManager(
    providers: [
      TestFeatureProvider(dependency: SomeDependency()),
    ],
    updateListener: (features) {
      print(
        'Features updated! '
        '\n${features.values.map((e) => e.toString()).join('\n')}',
      );
      print('');
    },
  );
}
6
likes
140
points
60
downloads

Publisher

verified publisherdart.nogipx.dev

Weekly Downloads

Dart package for flexible retrieving and managing feature flags.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

collection, logging, meta, rxdart

More

Packages that depend on feature_core