remote_config_feature_manager 2.0.0 copy "remote_config_feature_manager: ^2.0.0" to clipboard
remote_config_feature_manager: ^2.0.0 copied to clipboard

Firebase Remote Config feature manager for developer preferences, experiments, A/B tests etc.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:remote_config_feature_manager/remote_config_feature_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:provider/provider.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

import 'features.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  final SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  final RemoteConfigFeatureManager featureManager =
      await RemoteConfigFeatureManager.getInstance();
  await featureManager.activate(
    Features.values,
    minimumFetchInterval: const Duration(
      minutes: 5,
    ),
  );

  runApp(
    MultiProvider(
      providers: [
        Provider.value(
          value: sharedPreferences,
        ),
        Provider.value(
          value: featureManager,
        ),
      ],
      child: const MyApp(),
    ),
  );
}

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

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

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final bool isEnabled =
        context.read<RemoteConfigFeatureManager>().isEnabled(Features.booleanFeature);
    return Scaffold(
      appBar: AppBar(
        title: const Text('Feature Manager Demo Application'),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text.rich(
              TextSpan(
                text: 'Feature toggle ${Features.booleanFeature.remoteSourceKey} >>> ',
                children: <InlineSpan>[
                  TextSpan(
                    text: isEnabled ? 'enabled' : 'disabled',
                    style: TextStyle(
                      color: isEnabled ? Colors.green : Colors.red,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 16.0),
            ElevatedButton(
              child: const Text('Open developer preferences'),
              onPressed: () {
                Navigator.of(context)
                    .push(
                  MaterialPageRoute(
                    builder: (BuildContext context) => DeveloperPreferencesScreen(
                      featuresList: Features.values,
                      sharedPreferences: context.read(),
                    ),
                  ),
                )
                    .then((value) {
                  setState(() {});
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
140
pub points
27%
popularity

Publisher

verified publisherplayseek.io

Firebase Remote Config feature manager for developer preferences, experiments, A/B tests etc.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

feature_manager, firebase_remote_config, flutter, shared_preferences

More

Packages that depend on remote_config_feature_manager