Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Failure implement Exception #42

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**/.DS_Store

# IntelliJ related
*.iml
*.ipr
Expand Down
2 changes: 1 addition & 1 deletion kuama_core/lib/src/failures/failure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ExceptionCaught {
}

/// Maintainers: Keep same structure as [Error]/[Exception]
abstract class Failure {
abstract class Failure implements Exception {
final ExceptionCaught? exceptionCaught;

Failure({required this.exceptionCaught});
Expand Down
4 changes: 2 additions & 2 deletions kuama_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: kuama_core
description: A starting point for Dart libraries or applications.
publish_to: 'none'
version: 1.3.0
version: 1.3.1

environment:
sdk: '>=3.0.0 <4.0.0'
Expand All @@ -15,7 +15,7 @@ dependencies:
rxdart: '>=0.27.0 <0.29.0'

dev_dependencies:
mek_lints: ^1.0.0
mek_lints: ^4.0.0

test: ^1.21.1

Expand Down
3 changes: 3 additions & 0 deletions kuama_permissions/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ targets:
$default:
builders:
source_gen:combining_builder:
options:
ignore_for_file:
- unnecessary_parenthesis
generate_for:
exclude:
- test
Expand Down
1 change: 1 addition & 0 deletions kuama_permissions/lib/src/blocs/_permissions_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class _AskPermissionsEvent extends _PermissionsBlocEvent with _$_AskPermissionsE
class _ConfirmAskPermissionsEvent extends _PermissionsBlocEvent with _$_ConfirmAskPermissionsEvent {
final bool? canRequest;

// ignore: avoid_positional_boolean_parameters
_ConfirmAskPermissionsEvent(this.canRequest);

@override
Expand Down
86 changes: 29 additions & 57 deletions kuama_permissions/lib/src/blocs/_permissions_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class PermissionsBlocState with _$PermissionsBlocState {
final isAllEnabled = permissions
.map((e) => e.toService())
.whereNotNull()
.every((element) => servicesStatus[element] == true);
.every((element) => servicesStatus[element] ?? false);
if (!isAllEnabled) return true;
return permissions.any((permission) {
return permissionsStatus[permission] != PermissionStatus.granted;
Expand Down Expand Up @@ -235,15 +235,11 @@ class CheckingPermissionState extends PermissionsBlocState with _$CheckingPermis
final Set<Permission> payload;

const CheckingPermissionState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => true;
Expand All @@ -267,15 +263,11 @@ class CheckedPermissionState extends PermissionsBlocState with _$CheckedPermissi
final Set<Permission> payload;

const CheckedPermissionState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => false;
Expand All @@ -299,15 +291,11 @@ class RequestingPermissionsState extends PermissionsBlocState with _$RequestingP
final Set<Permission> payload;

const RequestingPermissionsState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => true;
Expand All @@ -334,16 +322,12 @@ class RequestedPermissionsState extends PermissionsBlocState with _$RequestedPer
final bool isRequested;

const RequestedPermissionsState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
required this.isRequested,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => false;
Expand All @@ -367,15 +351,11 @@ class AskingPermissionsState extends PermissionsBlocState with _$AskingPermissio
final Set<Permission> payload;

const AskingPermissionsState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => true;
Expand Down Expand Up @@ -403,16 +383,12 @@ class ConfirmableAskPermissionsState extends PermissionsBlocState
final bool isRestored;

const ConfirmableAskPermissionsState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
required this.isRestored,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => false;
Expand Down Expand Up @@ -441,17 +417,13 @@ class AskedPermissionsState extends PermissionsBlocState with _$AskedPermissions
final bool isRequested;

const AskedPermissionsState({
required bool isRefreshing,
required Map<Permission, PermissionStatus> permissionsStatus,
required Map<Service, bool> servicesStatus,
required super.isRefreshing,
required super.permissionsStatus,
required super.servicesStatus,
required this.payload,
required this.isCancelled,
required this.isRequested,
}) : super(
isRefreshing: isRefreshing,
permissionsStatus: permissionsStatus,
servicesStatus: servicesStatus,
);
});

@override
bool get isLoading => false;
Expand Down
1 change: 1 addition & 0 deletions kuama_permissions/lib/src/blocs/permissions_bloc.b.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class PermissionsBloc extends Bloc<_PermissionsBlocEvent, PermissionsBlocState>
/// If `null`, the request is discarded.
///
/// Note: The confirmation may be completed after a refresh. See [PermissionsBlocState.isRefreshing].
// ignore: avoid_positional_boolean_parameters
void confirmAsk(bool? canRequest) => add(_ConfirmAskPermissionsEvent(canRequest));

Future<void> _onEvent(_PermissionsBlocEvent event, Emitter<PermissionsBlocState> emit) async {
Expand Down
4 changes: 3 additions & 1 deletion kuama_permissions/lib/src/blocs/permissions_bloc.b.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class AppLifecycleStateRepository {
WidgetsBindingObserver? _observer;

static AppLifecycleStateRepository? _instance;
AppLifecycleStateRepository._();

/// It is a singleton because only one observer should exist
factory AppLifecycleStateRepository() {
return _instance ??= AppLifecycleStateRepository._();
}

AppLifecycleStateRepository._();

Stream<AppLifecycleState> get onChanges {
_subject ??= StreamController.broadcast(
sync: true,
Expand All @@ -29,6 +30,8 @@ class AppLifecycleStateRepository {

return _subject!.stream;
}

void dispose() => unawaited(_subject?.close());
}

class _Observer extends WidgetsBindingObserver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:permission_handler_platform_interface/permission_handler_platfor
class PermissionsManagerRepository {
PermissionHandlerPlatform get _handler => GetIt.I();

/// Returns [true] if the app settings page could be opened, otherwise [false].
/// Returns `true` if the app settings page could be opened, otherwise `false`.
Future<bool> openAppSettings() async {
return await _handler.openAppSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PermissionsService {
}

Stream<void> get onRequiredPermissionsRefresh async* {
AppLifecycleState prevState = AppLifecycleState.paused;
var prevState = AppLifecycleState.paused;
await for (final state in _appLifecycleState.onChanges) {
if (prevState != AppLifecycleState.resumed &&
prevState != AppLifecycleState.inactive &&
Expand Down
6 changes: 3 additions & 3 deletions kuama_permissions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: kuama_permissions
description: A starting point for Dart libraries or applications.
publish_to: 'none'
version: 1.3.0
version: 1.3.1

environment:
sdk: '>=3.0.0 <4.0.0'
Expand All @@ -20,7 +20,7 @@ dependencies:
git:
url: https://github.com/Kuama-IT/kuama_dart.git
path: kuama_core
ref: 1.3.0
ref: 1.3.1

permission_handler_platform_interface: ^4.2.1
permission_handler: ^11.3.1
Expand All @@ -36,7 +36,7 @@ dependencies:
mek_data_class: ^1.4.0

dev_dependencies:
mek_lints: ^1.0.0
mek_lints: ^4.0.0

flutter_test: { sdk: flutter }

Expand Down
12 changes: 6 additions & 6 deletions kuama_permissions/test/blocs/permissions_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void main() {
bloc = PermissionsBloc();
});

tearDown(GetIt.instance.reset);
tearDown(() async => Future.wait([GetIt.instance.reset(), onRequiredPermissionsRefresh.close()]));

group("PermissionsBloc", () {
group('PermissionsBloc', () {
const tPermission1 = Permission.storage;
const tPermission2 = Permission.camera;
const tPermissionService = Permission.location;
Expand All @@ -49,7 +49,7 @@ void main() {
group('PermissionsBloc.check', () {
test('cant check because cant operate', () {
bloc.emit(mockState);
var state = bloc.state;
final state = bloc.state;

when(() => mockState.checkCanCheck(any())).thenReturn(false);

Expand Down Expand Up @@ -123,7 +123,7 @@ void main() {
group('PermissionsBloc.request', () {
test('cant request because cant operate', () {
bloc.emit(mockState);
var state = bloc.state;
final state = bloc.state;

when(() => mockState.checkCanRequest(any())).thenReturn(false);

Expand Down Expand Up @@ -207,7 +207,7 @@ void main() {
group('PermissionsBloc.confirmAsk', () {
test('cant confirm ask because cant operate', () {
bloc.emit(mockState);
var state = bloc.state;
final state = bloc.state;

when(() => mockState.checkCanConfirmAsk(any())).thenReturn(false);

Expand Down Expand Up @@ -305,7 +305,7 @@ void main() {
group('PermissionsBloc.ask', () {
test('cant ask because cant operate', () {
bloc.emit(mockState);
var state = bloc.state;
final state = bloc.state;

when(() => mockState.checkCanAsk(any())).thenReturn(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: avoid_implementing_value_types

import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
import 'package:kuama_permissions/src/entities/permissions_status_entity.b.dart';
Expand Down Expand Up @@ -35,7 +37,7 @@ void main() {

tearDown(GetIt.instance.reset);

group("PermissionsService", () {
group('PermissionsService', () {
const tPermission1 = Permission.storage;
const tService = Permission.locationWhenInUse;

Expand Down
1 change: 1 addition & 0 deletions kuama_permissions/test/t_utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meta/meta.dart';

// ignore: avoid_void_async
void after(void Function() fn) async {
await Future.delayed(const Duration(milliseconds: 1));
fn();
Expand Down
2 changes: 1 addition & 1 deletion kuama_position/lib/src/blocs/_position_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _UpdateStatusEvent extends _PositionBlocEvent {
final bool hasPermissionGranted;
final bool isServiceEnabled;

const _UpdateStatusEvent(this.hasPermissionGranted, this.isServiceEnabled);
const _UpdateStatusEvent({required this.hasPermissionGranted, required this.isServiceEnabled});

@override
R map<R>({
Expand Down
Loading
Loading