WIP - Provider refactorings

This commit is contained in:
Anton Stubenbord
2022-12-27 00:12:33 +01:00
parent 60aecb549d
commit bf0e186646
53 changed files with 434 additions and 416 deletions

View File

@@ -1,9 +1,8 @@
import 'dart:io';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/security/security_context_aware_dio_manager.dart';
import 'package:paperless_mobile/core/security/authentication_aware_dio_manager.dart';
import 'package:paperless_mobile/core/store/local_vault.dart';
import 'package:paperless_mobile/features/login/bloc/authentication_state.dart';
import 'package:paperless_mobile/features/login/model/authentication_information.dart';
@@ -16,7 +15,7 @@ class AuthenticationCubit extends HydratedCubit<AuthenticationState> {
final LocalAuthenticationService _localAuthService;
final PaperlessAuthenticationApi _authApi;
final LocalVault _localVault;
final SecurityContextAwareDioManager _dioWrapper;
final AuthenticationAwareDioManager _dioWrapper;
AuthenticationCubit(
this._localVault,

View File

@@ -20,7 +20,7 @@ class AuthenticationState {
required this.wasLoginStored,
this.wasLocalAuthenticationSuccessful,
this.authentication,
});
}) : assert(!isAuthenticated || authentication != null);
AuthenticationState copyWith({
bool? wasLoginStored,

View File

@@ -92,12 +92,12 @@ class _LoginPageState extends State<LoginPage> {
setState(() => _isLoginLoading = true);
final form = _formKey.currentState!.value;
try {
await BlocProvider.of<AuthenticationCubit>(context).login(
credentials: form[UserCredentialsFormField.fkCredentials],
serverUrl: form[ServerAddressFormField.fkServerAddress],
clientCertificate:
form[ClientCertificateFormField.fkClientCertificate],
);
await context.read<AuthenticationCubit>().login(
credentials: form[UserCredentialsFormField.fkCredentials],
serverUrl: form[ServerAddressFormField.fkServerAddress],
clientCertificate:
form[ClientCertificateFormField.fkClientCertificate],
);
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
} on Map<String, dynamic> catch (error, stackTrace) {

View File

@@ -63,9 +63,9 @@ class _ServerAddressFormFieldState extends State<ServerAddressFormField> {
}
//https://stackoverflow.com/questions/49648022/check-whether-there-is-an-internet-connection-available-on-flutter-app
setState(() => _reachabilityStatus = ReachabilityStatus.testing);
final isReachable =
await Provider.of<ConnectivityStatusService>(context, listen: false)
.isServerReachable(address);
final isReachable = await context
.read<ConnectivityStatusService>()
.isServerReachable(address);
if (isReachable) {
setState(() => _reachabilityStatus = ReachabilityStatus.reachable);
} else {