local_config 0.0.4 copy "local_config: ^0.0.4" to clipboard
local_config: ^0.0.4 copied to clipboard

Make changes to your app's default behavior and appearance by changing parameter values — just like Firebase Remote Config, but locally.

example/lib/main.dart

import 'dart:async';

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

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

  LocalConfig.instance.initialize(
    parameters: {
      'feature_enabled': 'true',
      'api_base_url': 'https://api.myapp.com/v1',
      'retry_attempts': '3',
      'animation_speed': '1.25',
      'theme': '{"seedColor": "#2196F3", "darkMode": false}',
      'feature_enabled1': 'true',
      'api_base_url1': 'https://api.myapp.com/v1',
      'retry_attempts1': '3',
      'animation_speed1': '1.25',
      'theme1': '{"seedColor": "#2196F3", "darkMode": false}',
      'feature_enabled2': 'true',
      'api_base_url2': 'https://api.myapp.com/v1',
      'retry_attempts2': '3',
      'animation_speed2': '1.25',
      'theme2': '{"seedColor": "#2196F3", "darkMode": false}',
      'feature_enabled3': 'true',
      'api_base_url3': 'https://api.myapp.com/v1',
      'retry_attempts3': '3',
      'animation_speed3': '1.25',
      'theme3': '{"seedColor": "#2196F3", "darkMode": false}',
    },
  );

  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  static const title = 'Local Config Example';

  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      debugShowCheckedModeBanner: false,
      home: const ExamplePage(title: title),
    );
  }
}

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

  final String title;

  @override
  State<ExamplePage> createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  Map<String, String> _configs = {};
  StreamSubscription? _configSub;

  @override
  void initState() {
    super.initState();
    _configSub = LocalConfig.instance.onConfigUpdated.listen((configs) {
      setState(() => _configs = configs);
    });
  }

  @override
  void dispose() {
    _configSub?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
        actionsPadding: EdgeInsets.all(8),
        actions: [
          IconButton(
            onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute(
                  builder: (_) => LocalConfig.instance.entrypoint,
                ),
              );
            },
            tooltip: 'Local Config',
            icon: const Icon(Icons.settings),
          ),
        ],
      ),
      body: ListView.builder(
        itemCount: _configs.length,
        itemBuilder: (context, index) {
          final key = _configs.keys.elementAt(index);
          final value = _configs[key];

          return ListTile(
            title: Text(key),
            subtitle: Text(value?.toString() ?? 'null'),
          );
        },
      ),
    );
  }
}
0
likes
45
points
175
downloads

Publisher

unverified uploader

Weekly Downloads

Make changes to your app's default behavior and appearance by changing parameter values — just like Firebase Remote Config, but locally.

Repository (GitHub)
View/report issues

Topics

#local #config #management #persistence #storage

License

MIT (license)

Dependencies

flutter, flutter_localizations, flutter_secure_storage, get_it, intl, provider, re_editor, re_highlight, shared_preferences

More

Packages that depend on local_config