Skip to content

Commit

Permalink
feat: add web icons and adjust background detector with skipWeb bool
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-Zimmerman committed Feb 9, 2025
1 parent 9855a2b commit 3e73053
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ class AppInitializer {
}

/// Firebase
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform);
if (!kIsWeb && Platform.isAndroid) {
FirebaseMessaging.onBackgroundMessage(
_firebaseMessagingBackgroundHandler,
);
} else {
logger.i('Web or iOS - Skipping Firebase Messaging onBackgroundMessage');
logger
.i('Web or iOS - Skipping Firebase Messaging onBackgroundMessage');
}

if (defaultTargetPlatform == TargetPlatform.android) {
Expand Down Expand Up @@ -282,6 +284,7 @@ Future<void> main() async {
final config = await txClientViewModel.getConfig();
runApp(
BackgroundDetector(
skipWeb: true,
onLifecycleEvent: (AppLifecycleState state) => {
if (state == AppLifecycleState.resumed)
{
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/background_detector.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class BackgroundDetector extends StatefulWidget {
static BackgroundDetector? _instance;

static bool _skipWeb = false;

static bool get skipWeb => _skipWeb;
static set skipWeb(bool value) => _skipWeb = value;

factory BackgroundDetector({
Key? key,
bool skipWeb = false,
required Widget child,
void Function(AppLifecycleState)? onLifecycleEvent,
}) {
_skipWeb = skipWeb;
_instance ??= BackgroundDetector._internal(
key: key,
onLifecycleEvent: onLifecycleEvent,
Expand All @@ -35,6 +43,7 @@ class BackgroundDetector extends StatefulWidget {

/// Whether to globally ignore lifecycle events
static bool get ignore => _ignoreLifecycleEvents;

static set ignore(bool value) => _ignoreLifecycleEvents = value;

/// Temporarily ignore lifecycle events during [action].
Expand Down Expand Up @@ -69,6 +78,7 @@ class _BackgroundDetectorState extends State<BackgroundDetector>

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (BackgroundDetector.skipWeb == true && kIsWeb) return;
// Only emit if NOT ignoring
if (!BackgroundDetector.ignore) {
widget.onLifecycleEvent?.call(state);
Expand Down
Binary file modified web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed web/icons/Icon-192.png
Binary file not shown.
Binary file removed web/icons/Icon-512.png
Binary file not shown.
Binary file removed web/icons/Icon-maskable-192.png
Binary file not shown.
Binary file removed web/icons/Icon-maskable-512.png
Binary file not shown.
Binary file added web/icons/icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/icons/icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e73053

Please sign in to comment.