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.

122 lines
3.5 KiB

part of '../neon_files.dart';
2 years ago
class FilesChooseCreateDialog extends StatefulWidget {
2 years ago
const FilesChooseCreateDialog({
required this.bloc,
required this.basePath,
super.key,
});
final FilesBloc bloc;
final PathUri basePath;
2 years ago
@override
State<FilesChooseCreateDialog> createState() => _FilesChooseCreateDialogState();
}
class _FilesChooseCreateDialogState extends State<FilesChooseCreateDialog> {
Future<void> uploadFromPick(final FileType type) async {
2 years ago
final result = await FilePicker.platform.pickFiles(
allowMultiple: true,
type: type,
);
if (result != null) {
for (final file in result.files) {
await upload(File(file.path!));
}
}
}
Future<void> upload(final File file) async {
final sizeWarning = widget.bloc.options.uploadSizeWarning.value;
if (sizeWarning != null) {
final stat = file.statSync();
if (stat.size > sizeWarning) {
if (!(await showConfirmationDialog(
context,
FilesLocalizations.of(context).uploadConfirmSizeWarning(
filesize(sizeWarning),
filesize(stat.size),
),
))) {
return;
}
2 years ago
}
}
widget.bloc.uploadFile(
widget.basePath.join(PathUri.parse(p.basename(file.path))),
file.path,
);
2 years ago
}
@override
Widget build(final BuildContext context) => NeonDialog(
2 years ago
children: [
ListTile(
leading: Icon(
MdiIcons.filePlus,
color: Theme.of(context).colorScheme.primary,
),
title: Text(FilesLocalizations.of(context).uploadFiles),
2 years ago
onTap: () async {
await uploadFromPick(FileType.any);
2 years ago
if (mounted) {
Navigator.of(context).pop();
}
2 years ago
},
),
ListTile(
leading: Icon(
MdiIcons.fileImagePlus,
color: Theme.of(context).colorScheme.primary,
),
title: Text(FilesLocalizations.of(context).uploadImages),
2 years ago
onTap: () async {
await uploadFromPick(FileType.image);
2 years ago
if (mounted) {
Navigator.of(context).pop();
}
2 years ago
},
),
if (NeonPlatform.instance.canUseCamera) ...[
ListTile(
leading: Icon(
MdiIcons.cameraPlus,
color: Theme.of(context).colorScheme.primary,
),
title: Text(FilesLocalizations.of(context).uploadCamera),
onTap: () async {
Navigator.of(context).pop();
final picker = ImagePicker();
final result = await picker.pickImage(source: ImageSource.camera);
if (result != null) {
await upload(File(result.path));
}
},
),
],
2 years ago
ListTile(
leading: Icon(
MdiIcons.folderPlus,
color: Theme.of(context).colorScheme.primary,
),
title: Text(FilesLocalizations.of(context).folderCreate),
2 years ago
onTap: () async {
Navigator.of(context).pop();
final result = await showDialog<String>(
2 years ago
context: context,
builder: (final context) => const FilesCreateFolderDialog(),
);
if (result != null) {
widget.bloc.browser.createFolder(widget.basePath.join(PathUri.parse(result)));
2 years ago
}
},
),
],
);
}