A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

129 lines
4.2 KiB

import 'package:filesize/filesize.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:neon/utils.dart';
import 'package:neon/widgets.dart';
import 'package:neon_files/l10n/localizations.dart';
import 'package:neon_files/neon_files.dart';
import 'package:neon_files/widgets/dialog.dart';
import 'package:nextcloud/nextcloud.dart';
/// Displays a [FilesCreateFolderDialog] for creating a new folder.
///
/// Returns a future with the folder name split by `/`.
Future<String?> showFolderCreateDialog({
required final BuildContext context,
}) =>
showAdaptiveDialog<String>(
context: context,
builder: (final context) => const FilesCreateFolderDialog(),
);
/// Displays a [NeonConfirmationDialog] to confirm downloading a file larger
/// than the configured limit.
///
/// Returns a future whether the action has been accepted.
Future<bool> showDownloadConfirmationDialog(
final BuildContext context,
final int warningSize,
final int actualSize,
) async =>
await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
title: FilesLocalizations.of(context).optionsDownloadSizeWarning,
content: Text(
FilesLocalizations.of(context).downloadConfirmSizeWarning(
filesize(warningSize),
filesize(actualSize),
),
),
),
) ??
false;
/// Displays a [NeonConfirmationDialog] to confirm uploading a file larger than
/// the configured limit.
///
/// Returns a future whether the action has been accepted.
Future<bool> showUploadConfirmationDialog(
final BuildContext context,
final int warningSize,
final int actualSize,
) async =>
await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
title: FilesLocalizations.of(context).optionsUploadSizeWarning,
content: Text(
FilesLocalizations.of(context).uploadConfirmSizeWarning(
filesize(warningSize),
filesize(actualSize),
),
),
),
) ??
false;
/// Displays a [FilesChooseFolderDialog] to choose a new location for a file with the given [details].
///
/// Returns a future with the new location.
Future<PathUri?> showChooseFolderDialog(final BuildContext context, final FileDetails details) async {
final bloc = NeonProvider.of<FilesBloc>(context);
final originalUri = details.uri;
final b = bloc.getNewFilesBrowserBloc(initialUri: originalUri);
final result = await showDialog<PathUri>(
context: context,
builder: (final context) => FilesChooseFolderDialog(
bloc: b,
filesBloc: bloc,
originalPath: originalUri,
),
);
b.dispose();
return result;
}
/// Displays a [NeonConfirmationDialog] to confirm deleting a file or folder with the given [details].
///
/// Returns a future whether the action has been accepted.
Future<bool> showDeleteConfirmationDialog(final BuildContext context, final FileDetails details) async =>
await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
title: FilesLocalizations.of(context).actionDeleteTitle,
icon: const Icon(Icons.delete_outlined),
content: Text(
details.isDirectory
? FilesLocalizations.of(context).folderDeleteConfirm(details.name)
: FilesLocalizations.of(context).fileDeleteConfirm(details.name),
),
),
) ??
false;
/// Displays an adaptive modal to select or create a file.
Future<void> showFilesCreateModal(final BuildContext context) {
final theme = Theme.of(context);
final bloc = NeonProvider.of<FilesBloc>(context);
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.linux:
case TargetPlatform.windows:
return showModalBottomSheet(
context: context,
builder: (final _) => FilesChooseCreateModal(bloc: bloc),
);
case TargetPlatform.iOS:
case TargetPlatform.macOS:
return showCupertinoModalPopup(
context: context,
builder: (final _) => FilesChooseCreateModal(bloc: bloc),
);
}
}