|
| 1 | +// Copyright (c) Invertase Limited <[email protected]> & Contributors |
| 2 | +// ignore_for_file: public_member_api_docs |
| 3 | + |
| 4 | +import 'dart:async'; |
| 5 | +import 'dart:developer'; |
| 6 | +import 'package:firebase_core/firebase_core.dart'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | + |
| 9 | +void main() => runApp(const MyApp()); |
| 10 | + |
| 11 | +class MyApp extends StatelessWidget { |
| 12 | + const MyApp({super.key}); |
| 13 | + |
| 14 | + String get name => 'foo'; |
| 15 | + |
| 16 | + // fill app keys if needed, you can take ones from |
| 17 | + // https://github.com/invertase/flutterfire_desktop/blob/main/packages/firebase_core/firebase_core_desktop/example/lib/main.dart |
| 18 | + FirebaseOptions get firebaseOptions => const FirebaseOptions( |
| 19 | + appId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', |
| 20 | + apiKey: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', |
| 21 | + projectId: 'react-native-firebase-testing', |
| 22 | + messagingSenderId: 'zzzzzzzzzzzz', |
| 23 | + ); |
| 24 | + |
| 25 | + Future<void> initializeDefault() async { |
| 26 | + final FirebaseApp app = |
| 27 | + await Firebase.initializeApp(options: firebaseOptions); |
| 28 | + log('Initialized default app $app'); |
| 29 | + print('Initialized default app $app'); |
| 30 | + } |
| 31 | + |
| 32 | + Future<void> initializeSecondary() async { |
| 33 | + final FirebaseApp app = await Firebase.initializeApp( |
| 34 | + name: name, |
| 35 | + options: firebaseOptions, |
| 36 | + ); |
| 37 | + |
| 38 | + log('Initialized $app'); |
| 39 | + print('Initialized $app'); |
| 40 | + } |
| 41 | + |
| 42 | + void apps() { |
| 43 | + log('Currently initialized apps: ${Firebase.apps}'); |
| 44 | + print('Currently initialized apps: ${Firebase.apps}'); |
| 45 | + } |
| 46 | + |
| 47 | + void options() { |
| 48 | + final FirebaseApp app = Firebase.app(name); |
| 49 | + final FirebaseOptions options = app.options; |
| 50 | + log('Current options for app $name: $options'); |
| 51 | + print('Current options for app $name: $options'); |
| 52 | + } |
| 53 | + |
| 54 | + Future<void> delete() async { |
| 55 | + final FirebaseApp app = Firebase.app(name); |
| 56 | + await app.delete(); |
| 57 | + log('App $name deleted'); |
| 58 | + print('App $name deleted'); |
| 59 | + } |
| 60 | + |
| 61 | + @override |
| 62 | + Widget build(BuildContext context) { |
| 63 | + return MaterialApp( |
| 64 | + home: Scaffold( |
| 65 | + appBar: AppBar( |
| 66 | + title: const Text('Firebase Core example app'), |
| 67 | + ), |
| 68 | + body: Padding( |
| 69 | + padding: const EdgeInsets.all(20), |
| 70 | + child: Column( |
| 71 | + mainAxisAlignment: MainAxisAlignment.spaceAround, |
| 72 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 73 | + children: <Widget>[ |
| 74 | + ElevatedButton( |
| 75 | + onPressed: initializeDefault, |
| 76 | + child: const Text('Initialize default app'), |
| 77 | + ), |
| 78 | + ElevatedButton( |
| 79 | + onPressed: initializeSecondary, |
| 80 | + child: const Text('Initialize secondary app'), |
| 81 | + ), |
| 82 | + ElevatedButton( |
| 83 | + onPressed: apps, |
| 84 | + child: const Text('Get apps'), |
| 85 | + ), |
| 86 | + ElevatedButton( |
| 87 | + onPressed: options, |
| 88 | + child: const Text('List options'), |
| 89 | + ), |
| 90 | + ElevatedButton( |
| 91 | + onPressed: delete, |
| 92 | + child: const Text('Delete app'), |
| 93 | + ), |
| 94 | + ], |
| 95 | + ), |
| 96 | + ), |
| 97 | + ), |
| 98 | + ); |
| 99 | + } |
| 100 | +} |
0 commit comments