multi_frc 0.0.3 copy "multi_frc: ^0.0.3" to clipboard
multi_frc: ^0.0.3 copied to clipboard

Multiple Firebase Remote Config Helper

example/lib/main.dart

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

final apiKey = '';
final appIdAndroid = '';
final appIdIos = '';
final messagingSenderId = '';
final projectId = '';
final storageBucket = '';
final iosBundleId = '';

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

  await MultiFrc.init([
    MultiFrcOption(
      android: MultiFrc.option(
        apiKey: apiKey,
        appId: appIdAndroid,
        messagingSenderId: messagingSenderId,
        projectId: projectId,
        storageBucket: storageBucket,
      ),
      ios: MultiFrc.option(
        apiKey: apiKey,
        appId: appIdIos,
        messagingSenderId: messagingSenderId,
        projectId: projectId,
        storageBucket: storageBucket,
        iosBundleId: iosBundleId,
      ),
      web: null,
    ),
  ]);

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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;
  String get keyword => MultiFrc.getJson('json_test')['hello'] ?? '';
  List get counting => MultiFrc.getArray('array_test');
  Stream showBtnStream = MultiFrc.getBoolAsStream('bool_test');

  @override
  void initState() {
    super.initState();
    showBtnStream.listen((e) => debugPrint('$e'));

    // log remote config
    final rc = MultiFrc.instance(projectId);
    debugPrint('lastFetchStatus: ${rc.lastFetchStatus.name}');
    debugPrint('lastFetchTime: ${rc.lastFetchTime.toIso8601String()}');
  }

  @override
  void dispose() {
    MultiFrc.removeStream('show_btn');
    super.dispose();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Lets count: ${counting.join(', ')}!'),
            const Text('You have pushed the button this many times:'),
            Text(
              '$keyword $_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: StreamBuilder(
        stream: showBtnStream,
        builder: (context, snapshot) {
          return Visibility(
            visible: snapshot.data == true,
            child: FloatingActionButton(
              onPressed: _incrementCounter,
              tooltip: 'Increment',
              child: const Icon(Icons.add),
            ),
          );
        },
      ),
    );
  }
}
0
likes
150
points
12
downloads

Documentation

API reference

Publisher

verified publisherdigitalservice.id

Weekly Downloads

Multiple Firebase Remote Config Helper

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

firebase_core, firebase_remote_config, flutter

More

Packages that depend on multi_frc