refactoring

security update
This commit is contained in:
Mguy13 2022-12-25 22:17:59 +01:00
parent 1747ab0245
commit 78fe9e7b09
39 changed files with 289 additions and 132 deletions

View file

@ -1,8 +1,8 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mc_gallery/locator.dart';
import 'package:flutter/widgets.dart';
import '/locator.dart';
import 'logging_service.dart';
typedef AddLifeCycleListener = void Function({
@ -23,7 +23,8 @@ class AppLifecycleService with WidgetsBindingObserver {
final LoggingService _loggingService;
late final StreamController<AppLifecycleState> _streamController = StreamController.broadcast();
late final StreamController<AppLifecycleState> _lifecycleStateStreamController =
StreamController.broadcast();
final Map<String, StreamSubscription> _appLifecycleSubscriptions = {};
AppLifecycleState? _appLifeCycleState;
@ -43,14 +44,15 @@ class AppLifecycleService with WidgetsBindingObserver {
void didChangeAppLifecycleState(AppLifecycleState state) {
try {
_appLifeCycleState = state;
_streamController.add(state);
_lifecycleStateStreamController.add(state);
} catch (error, stackTrace) {
_loggingService.error(
'Something went wrong logging ${state.name} inside the didChangeAppLifeCycleState method',
'Something went wrong with ${state.name} inside the didChangeAppLifeCycleState method',
error,
stackTrace,
);
}
super.didChangeAppLifecycleState(state);
}
@ -61,17 +63,17 @@ class AppLifecycleService with WidgetsBindingObserver {
}) {
try {
if (_appLifecycleSubscriptions.containsKey(tag)) {
_loggingService.warning('Tag already active, returning!');
_loggingService.warning('Tag already active, returning');
} else {
final message = 'Adding $tag appLifecycleState listener';
_loggingService.info('$message..');
if (_appLifeCycleState != null && tryCallListenerOnAdd) listener(_appLifeCycleState!);
_appLifecycleSubscriptions[tag] = _streamController.stream.listen(listener);
_appLifecycleSubscriptions[tag] = _lifecycleStateStreamController.stream.listen(listener);
_loggingService.good('$message success!');
}
} catch (error, stackTrace) {
_loggingService.error(
'Something went wrong adding $tag appLifecycleState listener!',
'Something went wrong adding $tag appLifecycleState listener',
error,
stackTrace,
);
@ -88,11 +90,11 @@ class AppLifecycleService with WidgetsBindingObserver {
_appLifecycleSubscriptions.remove(tag);
_loggingService.good('$message success!');
} else {
_loggingService.warning('Subscription was not found!');
_loggingService.warning('Subscription was not found');
}
} catch (error, stackTrace) {
_loggingService.error(
'Something went wrong removing $tag appLifecycleState listener!',
'Something went wrong removing $tag appLifecycleState listener',
error,
stackTrace,
);

View file

@ -4,10 +4,10 @@ import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';
import '/features/core/services/logging_service.dart';
import '/locator.dart';
import 'logging_service.dart';
/// Used to observe the current connection type.
/// Used to observe the current connection type and status.
class ConnectionsService {
ConnectionsService({
required Connectivity connectivity,

View file

@ -1,7 +1,9 @@
import 'package:hive/hive.dart';
import 'package:mc_gallery/features/core/services/logging_service.dart';
import 'package:mc_gallery/locator.dart';
import '/locator.dart';
import 'logging_service.dart';
/// Handles storing state data locally, onto the device itself
class LocalStorageService {
LocalStorageService() {
_init();
@ -9,10 +11,10 @@ class LocalStorageService {
final LoggingService _loggingService = LoggingService.locate;
static const String _userBoxKey = 'userBoxKey';
late final Box<bool> _userBox;
static const String _userBoxKey = 'userBoxKey';
Future<void> _init() async {
_userBox = await Hive.openBox(_userBoxKey);

View file

@ -8,6 +8,7 @@ import 'package:talker_dio_logger/talker_dio_logger_settings.dart';
import '/locator.dart';
/// Handles logging of events.
class LoggingService {
final Talker _talker = Talker(
settings: TalkerSettings(

View file

@ -1,11 +1,12 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:mc_gallery/features/home/views/image_carousel/image_carousel_view.dart';
import 'package:mc_gallery/locator.dart';
import '/features/home/views/image_carousel/image_carousel_view.dart';
import '/locator.dart';
import '../abstracts/router/app_router.dart';
import '../abstracts/router/routes.dart';
/// Handles the navigation to and fro all the screens in the app.
class NavigationService {
const NavigationService({
required McgRouter mcgRouter,
@ -22,10 +23,5 @@ class NavigationService {
extra: imageCarouselViewArguments,
);
void backToGallery(BuildContext context) => context.pop();
void previous() {}
void next() {}
static NavigationService get locate => Locator.locate();
}

View file

@ -1,6 +1,7 @@
import 'package:flutter/widgets.dart';
import 'package:mc_gallery/features/core/services/logging_service.dart';
import 'package:mc_gallery/locator.dart';
import '/locator.dart';
import 'logging_service.dart';
class OverlayService {
OverlayService({