feature_manager 1.3.0 copy "feature_manager: ^1.3.0" to clipboard
feature_manager: ^1.3.0 copied to clipboard

Feature manager for developer preferences and experiments

example/lib/main.dart

import 'package:example/features.dart';
import 'package:feature_manager/feature_manager.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final sharedPreferences = await SharedPreferences.getInstance();
  final featureManager = await FeatureManager.getInstance();

  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 isEnabled = context.read<FeatureManager>().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 ',
                children: <InlineSpan>[
                  TextSpan(
                    text: isEnabled ? 'enabled' : 'disabled',
                    style: TextStyle(
                      color: isEnabled ? Colors.green : Colors.red,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              child: const Text('Open developer preferences'),
              onPressed: () {
                Navigator.of(context)
                    .push(
                  MaterialPageRoute<void>(
                    builder: (context) => DeveloperPreferencesScreen(
                      featuresList: Features.values,
                      sharedPreferences: context.read(),
                    ),
                  ),
                )
                    .then((value) {
                  setState(() {});
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
5
likes
140
pub points
45%
popularity

Publisher

verified publisherplayseek.io

Feature manager for developer preferences and experiments

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on feature_manager