Skip to content

Commit

Permalink
Merge branch '28902-change-pop-to-maybepop'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Pabon committed Nov 4, 2024
2 parents 5e6afbd + e10ee56 commit 80daa46
Show file tree
Hide file tree
Showing 28 changed files with 1,022 additions and 903 deletions.
9 changes: 5 additions & 4 deletions lib/app/mixins/repo_actions_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mixin RepositoryActionsMixin on LoggyType {
actions: [
TextButton(
child: Text(S.current.actionCloseCapital),
onPressed: () => Navigator.of(context).pop(false),
onPressed: () async => await Navigator.of(context).maybePop(false),
),
],
);
Expand Down Expand Up @@ -205,11 +205,12 @@ mixin RepositoryActionsMixin on LoggyType {
Fields.dialogActions(context, buttons: [
NegativeButton(
text: S.current.actionCancelCapital,
onPressed: () => Navigator.of(context).pop(false),
onPressed: () async =>
await Navigator.of(context).maybePop(false),
buttonsAspectRatio: Dimensions.aspectRatioModalDialogButton),
PositiveButton(
text: S.current.actionDeleteCapital,
onPressed: () => Navigator.of(context).pop(true),
onPressed: () async => await Navigator.of(context).maybePop(true),
buttonsAspectRatio: Dimensions.aspectRatioModalDialogButton,
isDangerButton: true,
)
Expand All @@ -220,7 +221,7 @@ mixin RepositoryActionsMixin on LoggyType {

if (deleteRepo ?? false) {
await Dialogs.executeFutureWithLoadingDialog(
context,
null,
reposCubit.deleteRepository(repoLocation),
);

Expand Down
20 changes: 13 additions & 7 deletions lib/app/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ class _MainPageState extends State<MainPage>
actions: [
TextButton(
child: Text(S.current.actionSkip.toUpperCase()),
onPressed: () => Navigator.of(context).pop(false),
onPressed: () async =>
await Navigator.of(context).maybePop(false),
),
TextButton(
child: Text(S.current.actionInstallDokan.toUpperCase()),
onPressed: () => Navigator.of(context).pop(true),
onPressed: () async =>
await Navigator.of(context).maybePop(true),
)
],
),
Expand Down Expand Up @@ -276,11 +278,13 @@ class _MainPageState extends State<MainPage>
actions: [
TextButton(
child: Text(S.current.actionSkip.toUpperCase()),
onPressed: () => Navigator.of(context).pop(false),
onPressed: () async =>
Navigator.of(context).maybePop(false),
),
TextButton(
child: Text(S.current.actionInstallDokan.toUpperCase()),
onPressed: () => Navigator.of(context).pop(true),
onPressed: () async =>
await Navigator.of(context).maybePop(true),
)
],
),
Expand Down Expand Up @@ -341,8 +345,9 @@ class _MainPageState extends State<MainPage>
actions: [
TextButton(
child: Text(S.current.actionCloseCapital),
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
onPressed: () async =>
await Navigator.of(context, rootNavigator: true)
.maybePop(false),
)
],
),
Expand Down Expand Up @@ -1048,7 +1053,8 @@ class _MainPageState extends State<MainPage>
])),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
onPressed: () async =>
await Navigator.of(context).maybePop(),
child: Text(S.current.actionCloseCapital))
]);
});
Expand Down
3 changes: 2 additions & 1 deletion lib/app/pages/qr_scanner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class _QRScannerState extends State<QRScanner> with AppLogger {

loggy.debug('Barcode found! $code');
scanned = true;
Navigator.of(context).pop(code);

await Navigator.of(context).maybePop(code);
}
});
}
Expand Down
9 changes: 5 additions & 4 deletions lib/app/pages/repo_import_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class RepoImportPage extends StatelessWidget {
final result = await parseShareToken(reposCubit, data);
switch (result) {
case ShareTokenValid(value: final token):
Navigator.of(context).pop(RepoImportFromToken(token));
await Navigator.of(context)
.maybePop(RepoImportFromToken(token));
case ShareTokenInvalid(error: final error):
showSnackBar(error.toString());
}
Expand Down Expand Up @@ -198,8 +199,8 @@ class RepoImportPage extends StatelessWidget {
_buildButton(
S.current.actionAddRepository.toUpperCase(),
switch (state) {
ShareTokenValid(value: final token) => () =>
Navigator.of(context).pop(RepoImportFromToken(token)),
ShareTokenValid(value: final token) => () async =>
await Navigator.of(context).maybePop(RepoImportFromToken(token)),
ShareTokenInvalid() || null => null,
},
);
Expand Down Expand Up @@ -231,7 +232,7 @@ class RepoImportPage extends StatelessWidget {

await Future.wait(locations.map(reposCubit.importRepoFromLocation));

Navigator.of(context).pop(RepoImportFromFiles(locations));
await Navigator.of(context).maybePop(RepoImportFromFiles(locations));
}),
],
);
Expand Down
2 changes: 1 addition & 1 deletion lib/app/pages/repo_qr_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _RepositoryQRPageState extends State<RepositoryQRPage> {
appBar: DirectionalAppBar(
leading: Fields.actionIcon(
const Icon(Icons.close, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
onPressed: () async => await Navigator.of(context).maybePop(),
),
backgroundColor: Colors.transparent,
),
Expand Down
8 changes: 4 additions & 4 deletions lib/app/pages/repo_security_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class RepoSecurityPage extends StatelessWidget {
actions: [
TextButton(
child: Text(S.current.actionCancel),
onPressed: () => Navigator.of(context).pop(false)),
onPressed: () async => await Navigator.of(context).maybePop(false)),
TextButton(
child: Text(S.current.actionDiscard),
onPressed: () => Navigator.of(context).pop(true))
onPressed: () async => await Navigator.of(context).maybePop(true))
],
).then((pop) {
if (pop ?? false) {
Expand Down Expand Up @@ -131,10 +131,10 @@ class RepoSecurityPage extends StatelessWidget {
actions: [
TextButton(
child: Text(S.current.actionCancel),
onPressed: () => Navigator.of(context).pop(false)),
onPressed: () async => await Navigator.of(context).maybePop(false)),
TextButton(
child: Text(S.current.actionAccept),
onPressed: () => Navigator.of(context).pop(true))
onPressed: () async => await Navigator.of(context).maybePop(true))
],
);

Expand Down
47 changes: 26 additions & 21 deletions lib/app/utils/dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import 'package:build_context_provider/build_context_provider.dart';
import 'package:flutter/material.dart';

import '../../generated/l10n.dart';
import '../cubits/cubits.dart';
import '../widgets/widgets.dart';
import 'utils.dart';
import '../cubits/cubits.dart' show RepoCubit;
import '../widgets/widgets.dart'
show ActionsDialog, NegativeButton, PositiveButton;
import 'utils.dart'
show AppThemeExtension, Dimensions, Fields, Strings, ThemeGetter;

abstract class Dialogs {
static Future<T> executeWithLoadingDialog<T>(
BuildContext context, Future<T> func()) {
BuildContext? context, Future<T> Function() func) {
return executeFutureWithLoadingDialog(context, func());
}

Expand All @@ -26,11 +28,11 @@ abstract class Dialogs {
}

static void _showLoadingDialog(BuildContext? context) => context != null
? _loadingDialog(context)
: WidgetsBinding.instance
.addPostFrameCallback((_) => BuildContextProvider()(_loadingDialog));
? unawaited(_loadingDialog(context))
: WidgetsBinding.instance.addPostFrameCallback(
(_) => BuildContextProvider()((c) => unawaited(_loadingDialog(c))));

static Future<void> _loadingDialog(BuildContext context) => showDialog(
static Future<void> _loadingDialog(BuildContext context) async => showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => PopScope(
Expand All @@ -42,10 +44,10 @@ abstract class Dialogs {
),
));

static _hideLoadingDialog(BuildContext? context) => context != null
? _popDialog(context)
: BuildContextProvider()
.call((globalContext) => _popDialog(globalContext));
static void _hideLoadingDialog(BuildContext? context) =>
WidgetsBinding.instance.addPostFrameCallback((_) => context != null
? _popDialog(context)
: BuildContextProvider().call((c) => _popDialog(c)));

static void _popDialog(BuildContext context) =>
Navigator.of(context, rootNavigator: true).pop();
Expand Down Expand Up @@ -81,10 +83,10 @@ abstract class Dialogs {
[
TextButton(
child: Text(S.current.actionCloseCapital),
onPressed: () => Navigator.of(
onPressed: () async => await Navigator.of(
context,
rootNavigator: true,
).pop(false),
).maybePop(false),
),
],
);
Expand Down Expand Up @@ -134,16 +136,17 @@ abstract class Dialogs {
Fields.dialogActions(context, buttons: [
NegativeButton(
text: S.current.actionCancel,
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(),
onPressed: () async =>
await Navigator.of(context, rootNavigator: true)
.maybePop(),
buttonsAspectRatio:
Dimensions.aspectRatioModalDialogButton),
PositiveButton(
text: S.current.actionDelete,
isDangerButton: true,
onPressed: () async {
await repo.deleteFile(path);
Navigator.of(context).pop(fileName);
await Navigator.of(context).maybePop(fileName);
},
buttonsAspectRatio: Dimensions.aspectRatioModalDialogButton)
])
Expand Down Expand Up @@ -171,15 +174,17 @@ abstract class Dialogs {
buttons: [
NegativeButton(
text: S.current.actionCancel,
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
onPressed: () async =>
await Navigator.of(context, rootNavigator: true)
.maybePop(false),
buttonsAspectRatio: Dimensions.aspectRatioModalDialogButton,
),
PositiveButton(
text: S.current.actionDelete,
isDangerButton: true,
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(true),
onPressed: () async =>
await Navigator.of(context, rootNavigator: true)
.maybePop(true),
buttonsAspectRatio: Dimensions.aspectRatioModalDialogButton,
),
],
Expand Down
4 changes: 1 addition & 3 deletions lib/app/utils/file_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ class FileIO with AppLogger {
}

Future<bool> _maybeRequestPermission(BuildContext context) async {
if (!io.Platform.isAndroid &&
!io.Platform.isIOS &&
!io.Platform.isWindows) {
if (!io.Platform.isAndroid) {
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/app/utils/local_auth.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:io';
import 'package:flutter/material.dart';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:local_auth/local_auth.dart';

import '../../generated/l10n.dart';

abstract class LocalAuth {
Expand Down Expand Up @@ -55,9 +57,7 @@ abstract class LocalAuth {
Future<bool> _debugAuthenticate(BuildContext context, String reason) async {
Widget button(context, text, value) => TextButton(
child: Text(text),
onPressed: () {
Navigator.of(context).pop(value);
},
onPressed: () => Navigator.of(context).pop(value),
);

bool? authenticated = await showDialog(
Expand Down
19 changes: 11 additions & 8 deletions lib/app/utils/permissions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

import '../../generated/l10n.dart';
import 'utils.dart';
import 'utils.dart' show Dialogs, Dimensions;

class Permissions {
static Future<PermissionStatus> requestPermission(
Expand Down Expand Up @@ -42,22 +42,25 @@ class Permissions {
? <Widget>[
TextButton(
child: Text(S.current.actionCloseCapital),
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
onPressed: () async =>
await Navigator.of(context, rootNavigator: true)
.maybePop(false),
),
TextButton(
child: Text(S.current.actionGoToSettings.toUpperCase()),
onPressed: () {
openAppSettings();
onPressed: () async {
await openAppSettings();

Navigator.of(context, rootNavigator: true).pop(true);
await Navigator.of(context, rootNavigator: true)
.maybePop(true);
})
]
: <Widget>[
TextButton(
child: Text(S.current.actionCloseCapital),
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
onPressed: () async =>
await Navigator.of(context, rootNavigator: true)
.maybePop(false),
)
];

Expand Down
1 change: 1 addition & 0 deletions lib/app/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export 'hotspot.dart';
export 'inline_text_styles.dart';
export 'local_auth.dart';
export 'log.dart';
export 'master_key.dart';
export 'log_reader.dart';
export 'move_entry.dart';
export 'password_hasher.dart';
Expand Down
17 changes: 9 additions & 8 deletions lib/app/widgets/bars/sort_contents_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../generated/l10n.dart';
import '../../cubits/cubits.dart';
import '../../models/models.dart';
import '../../utils/utils.dart';
import '../buttons/sort_by_button.dart';
import '../buttons/sort_direction_button.dart';
import '../../cubits/cubits.dart'
show ReposCubit, SortBy, SortDirection, SortListCubit, SortListState;
import '../../models/models.dart' show OpenRepoEntry;
import '../../utils/utils.dart'
show AppLogger, Dialogs, Dimensions, Fields, StringExtension;
import '../widgets.dart' show SortByButton, SortDirectionButton;

class SortContentsBar extends StatefulWidget {
const SortContentsBar(
Expand Down Expand Up @@ -150,7 +151,7 @@ class _SortByList extends StatelessWidget with AppLogger {
textOverflow: TextOverflow.ellipsis,
textSoftWrap: false,
style: settingStyle,
onTap: () {
onTap: () async {
_sortCubit.sortBy(sortByItem);

if (_reposCubit.showList) {
Expand All @@ -160,8 +161,8 @@ class _SortByList extends StatelessWidget with AppLogger {
}

if (_reposCubit.currentRepo is OpenRepoEntry) {
Dialogs.executeFutureWithLoadingDialog(
context,
await Dialogs.executeFutureWithLoadingDialog(
null,
(_reposCubit.currentRepo as OpenRepoEntry)
.cubit
.refresh(
Expand Down
Loading

0 comments on commit 80daa46

Please sign in to comment.