Skip to content

Commit

Permalink
Fix dart analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed Dec 2, 2024
1 parent 30da2e9 commit a9e6ebd
Show file tree
Hide file tree
Showing 33 changed files with 64 additions and 114 deletions.
4 changes: 2 additions & 2 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ class ErrorScreen extends StatelessWidget {
// resulting in black screens. This class should help us find those race conditions.
class _AppNavigatorObserver extends NavigatorObserver {
final int _maxHistoryLength = 16;
List<_RouteHistoryEntry> _stackHistory = [];
Loggy<AppLogger> _logger;
final List<_RouteHistoryEntry> _stackHistory = [];
final Loggy<AppLogger> _logger;

_AppNavigatorObserver(this._logger);

Expand Down
3 changes: 0 additions & 3 deletions lib/app/cubits/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ import 'package:stream_transform/stream_transform.dart';

import '../../generated/l10n.dart';
import '../models/models.dart';
import '../utils/master_key.dart';
import '../utils/mounter.dart';
import '../utils/repo_path.dart' as repo_path;
import '../utils/utils.dart';
import 'cubits.dart';
import 'utils.dart';

class RepoState extends Equatable {
final bool isLoading;
Expand Down
38 changes: 20 additions & 18 deletions lib/app/cubits/repo_security.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import '../models/models.dart'
AuthModeKeyStoredOnDevice,
AuthModePasswordStoredOnDevice,
UnlockedAccess,
LocalSecret,
LocalSecretKeyAndSalt,
LocalSecretInput,
LocalSecretKey,
LocalSecretManual,
LocalSecretMode,
LocalSecretRandom,
Expand Down Expand Up @@ -56,7 +54,7 @@ class RepoSecurityState {

final SecretKeyOrigin plannedOrigin;
final bool plannedStoreSecret;
final _TriBool plannedWithBiometrics;
final BiometricsValue plannedWithBiometrics;
final Option<LocalPassword> plannedPassword;

final bool isBiometricsAvailable;
Expand All @@ -65,20 +63,20 @@ class RepoSecurityState {
required this.current,
SecretKeyOrigin? plannedOrigin,
bool? plannedStoreSecret,
_TriBool? plannedWithBiometrics,
BiometricsValue? plannedWithBiometrics,
this.plannedPassword = const None(),
this.isBiometricsAvailable = false,
}) : plannedOrigin = plannedOrigin ?? current.localSecretMode.origin,
plannedStoreSecret =
plannedStoreSecret ?? current.localSecretMode.store.isStored,
plannedWithBiometrics = plannedWithBiometrics ??
_TriBool(current.localSecretMode.isSecuredWithBiometrics);
BiometricsValue(current.localSecretMode.isSecuredWithBiometrics);

RepoSecurityState copyWith({
RepoSecurityCurrentState? current,
SecretKeyOrigin? plannedOrigin,
bool? plannedStoreSecret,
_TriBool? plannedWithBiometrics,
BiometricsValue? plannedWithBiometrics,
Option<LocalPassword>? plannedPassword,
bool? isBiometricsAvailable,
}) =>
Expand Down Expand Up @@ -217,12 +215,12 @@ class RepoSecurityCubit extends Cubit<RepoSecurityState>
void setStore(bool value) {
final plannedWithBiometrics =
switch ((value, state.plannedWithBiometrics)) {
(true, _True()) => _True(),
(true, _False()) => _False(),
(true, _ImpliedFalse()) => _True(),
(false, _True()) => _ImpliedFalse(),
(false, _False()) => _False(),
(false, _ImpliedFalse()) => _ImpliedFalse(),
(true, BiometricsTrue()) => BiometricsTrue(),
(true, BiometricsFalse()) => BiometricsFalse(),
(true, BiometricsImpliedFalse()) => BiometricsTrue(),
(false, BiometricsTrue()) => BiometricsImpliedFalse(),
(false, BiometricsFalse()) => BiometricsFalse(),
(false, BiometricsImpliedFalse()) => BiometricsImpliedFalse(),
};

emitUnlessClosed(state.copyWith(
Expand All @@ -231,7 +229,8 @@ class RepoSecurityCubit extends Cubit<RepoSecurityState>
}

void setSecureWithBiometrics(bool value) {
emitUnlessClosed(state.copyWith(plannedWithBiometrics: _TriBool(value)));
emitUnlessClosed(
state.copyWith(plannedWithBiometrics: BiometricsValue(value)));
}

void setLocalPassword(String? value) {
Expand Down Expand Up @@ -376,21 +375,24 @@ Future<(LocalSecretKeyAndSalt?, AuthMode)> _computeLocalSecretAndAuthMode(

//--------------------------------------------------------------------

sealed class _TriBool {
sealed class BiometricsValue {
bool get toBool;

factory _TriBool(bool b) => b ? _True() : _False();
factory BiometricsValue(bool b) => b ? BiometricsTrue() : BiometricsFalse();
}

class _True implements _TriBool {
class BiometricsTrue implements BiometricsValue {
@override
bool get toBool => true;
}

class _False implements _TriBool {
class BiometricsFalse implements BiometricsValue {
@override
bool get toBool => false;
}

class _ImpliedFalse implements _TriBool {
class BiometricsImpliedFalse implements BiometricsValue {
@override
bool get toBool => false;
}

Expand Down
1 change: 0 additions & 1 deletion lib/app/cubits/repos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:ouisync/state_monitor.dart';

import '../../generated/l10n.dart';
import '../models/models.dart';
import '../utils/mounter.dart';
import '../utils/utils.dart';
import 'cubits.dart';

Expand Down
2 changes: 2 additions & 0 deletions lib/app/models/access_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BlindAccess implements Access {
}

class ReadAccess implements Access, UnlockedAccess {
@override
LocalSecret localSecret;

ReadAccess(this.localSecret);
Expand All @@ -90,6 +91,7 @@ class ReadAccess implements Access, UnlockedAccess {
}

class WriteAccess implements Access, UnlockedAccess {
@override
LocalSecret localSecret;

WriteAccess(this.localSecret);
Expand Down
9 changes: 0 additions & 9 deletions lib/app/pages/onboarding_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:introduction_screen/introduction_screen.dart';
import 'language_picker_page.dart';
import 'accept_eq_values_terms_privacy_page.dart';
import '../../generated/l10n.dart';
import '../utils/click_counter.dart';
import '../cubits/locale.dart';
import '../utils/utils.dart';

Expand Down Expand Up @@ -188,14 +187,6 @@ class _OnboardingPageState extends State<OnboardingPage> {
width: _imageWidth * 0.6,
);

Widget _buildButton(String text) => Fields.inPageButton(
text: text,
size: Dimensions.sizeInPageButtonMicro,
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
foregroundColor: Theme.of(context).colorScheme.surfaceTint,
onPressed: null,
);

// For debugging
//@override
//String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) =>
Expand Down
35 changes: 13 additions & 22 deletions lib/app/pages/repo_reset_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ import '../models/auth_mode.dart';
import '../models/access_mode.dart';
import '../cubits/cubits.dart' show RepoCubit, RepoState;
import '../utils/utils.dart'
show
AppThemeExtension,
Constants,
Dimensions,
Fields,
LocalAuth,
Settings,
ThemeGetter;
show AppThemeExtension, Constants, Fields, LocalAuth, Settings, ThemeGetter;
import '../widgets/widgets.dart'
show ActionsDialog, DirectionalAppBar, PositiveButton, NegativeButton;

Expand All @@ -34,9 +27,7 @@ class RepoResetAccessPage extends StatefulWidget {
builder: (context) =>
RepoResetAccessPage._(repo, startAccess, settings));

Navigator.push(context, route);

return (await route.popped)!;
return (await Navigator.push(context, route)) ?? startAccess;
}

RepoResetAccessPage._(
Expand All @@ -51,13 +42,13 @@ class RepoResetAccessPage extends StatefulWidget {
}

class RepoResetAccessPageState extends State<RepoResetAccessPage> {
_TokenStatus tokenStatus;
_TokenStatus _tokenStatus;
Access currentAccess;

RepoResetAccessPageState(this.currentAccess)
: tokenStatus = _InvalidTokenStatus(_InvalidTokenType.empty);
: _tokenStatus = _InvalidTokenStatus(_InvalidTokenType.empty);

bool get hasPendingChanges => tokenStatus is _SubmitableTokenStatus;
bool get hasPendingChanges => _tokenStatus is _SubmitableTokenStatus;

@override
Widget build(BuildContext context) => PopScope(
Expand Down Expand Up @@ -171,7 +162,7 @@ class RepoResetAccessPageState extends State<RepoResetAccessPage> {
}

Widget _buildTokenInfo() {
final info = switch (tokenStatus) {
final info = switch (_tokenStatus) {
_SubmitableTokenStatus status =>
_capitalized(status.inputToken.accessMode.localized),
_SubmittedTokenStatus status =>
Expand All @@ -192,13 +183,13 @@ class RepoResetAccessPageState extends State<RepoResetAccessPage> {

// Capitalize first letter of a string
String _capitalized(String str) {
return str.length > 0
return str.isNotEmpty
? '${str[0].toUpperCase()}${str.substring(1).toLowerCase()}'
: str;
}

Widget _buildActionInfo() {
final (action, warning) = switch (tokenStatus) {
final (action, warning) = switch (_tokenStatus) {
_SubmitableTokenStatus status => _buildTokenStatusSubmitable(status),
_SubmittedTokenStatus status => _buildTokenStatusSubmitted(status),
_InvalidTokenStatus status => _buildTokenStatusInvalid(status),
Expand Down Expand Up @@ -281,7 +272,7 @@ class RepoResetAccessPageState extends State<RepoResetAccessPage> {
suffixIcon: const Icon(Icons.key_rounded),
onChanged: (input) {
widget._jobs.addJob(() async {
final inputToken = await parseTokenInput(input);
final inputToken = await _parseTokenInput(input);
_updateTokenStatusOnTokenInputChange(inputToken);
});
},
Expand All @@ -292,7 +283,7 @@ class RepoResetAccessPageState extends State<RepoResetAccessPage> {
Widget _buildSubmitButton() {
Future<void> Function()? onPressed;

switch (tokenStatus) {
switch (_tokenStatus) {
case _SubmitableTokenStatus valid:
onPressed = () async {
if (await _confirmUpdateDialog()) {
Expand Down Expand Up @@ -403,7 +394,7 @@ class RepoResetAccessPageState extends State<RepoResetAccessPage> {
await repo.setAuthMode(newAuthMode);

setState(() {
tokenStatus = _SubmittedTokenStatus(input);
_tokenStatus = _SubmittedTokenStatus(input);
this.currentAccess = currentAccess;
});
}
Expand All @@ -427,14 +418,14 @@ class RepoResetAccessPageState extends State<RepoResetAccessPage> {

if (mounted) {
setState(() {
tokenStatus = newStatus;
_tokenStatus = newStatus;
});
}
}

// -----------------------------------------------------------------

Future<_InputToken> parseTokenInput(String input) async {
Future<_InputToken> _parseTokenInput(String input) async {
if (input.isEmpty) {
return _InvalidInputToken.empty();
}
Expand Down
10 changes: 3 additions & 7 deletions lib/app/pages/repo_security_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import '../../generated/l10n.dart';
import '../pages/repo_reset_access.dart';
import '../cubits/cubits.dart'
show RepoCubit, RepoSecurityCubit, RepoSecurityState;
import '../models/models.dart'
show Access, UnlockedAccess, BlindAccess, ReadAccess, WriteAccess;
import '../models/models.dart' show UnlockedAccess;
import '../utils/utils.dart'
show
AppThemeExtension,
Dialogs,
Dimensions,
Fields,
PasswordHasher,
Settings,
Expand All @@ -26,10 +24,8 @@ import '../widgets/widgets.dart'
DirectionalAppBar,
LinkStyleAsyncButton,
CustomAdaptiveSwitch,
PasswordValidation,
ScrollableTextWidget;
PasswordValidation;
import '../models/models.dart' show SecretKeyOrigin;
import '../utils/platform/platform_values.dart' show PlatformValues;

//--------------------------------------------------------------------

Expand Down Expand Up @@ -125,7 +121,7 @@ class _State extends State<RepoSecurityPage> {
final newAccess = await RepoResetAccessPage.show(
access, context, widget.repo, widget.settings);

final unlockedAccess = newAccess?.asUnlocked;
final unlockedAccess = newAccess.asUnlocked;

if (unlockedAccess == null) {
Navigator.pop(context);
Expand Down
3 changes: 1 addition & 2 deletions lib/app/utils/dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import '../../generated/l10n.dart';
import '../cubits/cubits.dart' show RepoCubit;
import '../widgets/widgets.dart'
show ActionsDialog, NegativeButton, PositiveButton;
import 'utils.dart'
show AppThemeExtension, Dimensions, Fields, Strings, ThemeGetter;
import 'utils.dart' show AppThemeExtension, Fields, Strings, ThemeGetter;

abstract class Dialogs {
static int _loadingInvocations = 0;
Expand Down
1 change: 0 additions & 1 deletion lib/app/utils/settings/v1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:shared_preferences/shared_preferences.dart';

import '../../models/models.dart';
import '../files.dart';
import '../master_key.dart';
import '../utils.dart';
import 'atomic_shared_prefs_settings_key.dart';
import 'v0/v0.dart' as v0;
Expand Down
2 changes: 0 additions & 2 deletions lib/app/utils/settings/v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import 'package:path/path.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../models/models.dart';
import '../master_key.dart';
import '../utils.dart';
import '../option.dart';
import 'atomic_shared_prefs_settings_key.dart';
import 'v1.dart' as v1;

Expand Down
2 changes: 0 additions & 2 deletions lib/app/widgets/bars/repositories_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import '../../cubits/cubits.dart';
import '../../models/models.dart';
import '../../utils/utils.dart';
import '../notification_badge.dart';
import '../repo_status.dart';
import '../throughput_display.dart';
import '../widgets.dart';

class RepositoriesBar extends StatelessWidget
Expand Down
2 changes: 1 addition & 1 deletion lib/app/widgets/buttons/dialog_negative_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NegativeButton extends StatelessWidget {
this.buttonConstrains = Dimensions.sizeConstrainsDialogAction,
this.focusNode,
super.key,
}) : this.buttonsAspectRatio =
}) : buttonsAspectRatio =
buttonsAspectRatio ?? Dimensions.aspectRatioModalDialogButton;

final String? text;
Expand Down
4 changes: 2 additions & 2 deletions lib/app/widgets/buttons/dialog_positive_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import 'package:flutter/material.dart';
import '../../utils/utils.dart';

class PositiveButton extends StatelessWidget {
const PositiveButton({
PositiveButton({
required this.text,
required this.onPressed,
double? buttonsAspectRatio,
this.buttonConstrains = Dimensions.sizeConstrainsDialogAction,
this.focusNode,
this.isDangerButton = false,
super.key,
}) : this.buttonsAspectRatio =
}) : buttonsAspectRatio =
buttonsAspectRatio ?? Dimensions.aspectRatioModalDialogButton;

final String? text;
Expand Down
2 changes: 1 addition & 1 deletion lib/app/widgets/buttons/link_style_async_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LinkStyleAsyncButton extends StatefulWidget {
LinkStyleAsyncButton({
super.key,
required this.text,
this.onTap = null,
this.onTap,
});

final String text;
Expand Down
Loading

0 comments on commit a9e6ebd

Please sign in to comment.