|
|
@ -1,6 +1,6 @@ |
|
|
|
part of '../app.dart'; |
|
|
|
part of '../app.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class FilesChooseCreateDialog extends StatelessWidget { |
|
|
|
class FilesChooseCreateDialog extends StatefulWidget { |
|
|
|
const FilesChooseCreateDialog({ |
|
|
|
const FilesChooseCreateDialog({ |
|
|
|
required this.bloc, |
|
|
|
required this.bloc, |
|
|
|
required this.basePath, |
|
|
|
required this.basePath, |
|
|
@ -10,18 +10,42 @@ class FilesChooseCreateDialog extends StatelessWidget { |
|
|
|
final FilesBloc bloc; |
|
|
|
final FilesBloc bloc; |
|
|
|
final List<String> basePath; |
|
|
|
final List<String> basePath; |
|
|
|
|
|
|
|
|
|
|
|
Future upload(final FileType type) async { |
|
|
|
@override |
|
|
|
|
|
|
|
State<FilesChooseCreateDialog> createState() => _FilesChooseCreateDialogState(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _FilesChooseCreateDialogState extends State<FilesChooseCreateDialog> { |
|
|
|
|
|
|
|
Future uploadFromPick(final FileType type) async { |
|
|
|
final result = await FilePicker.platform.pickFiles( |
|
|
|
final result = await FilePicker.platform.pickFiles( |
|
|
|
allowMultiple: true, |
|
|
|
allowMultiple: true, |
|
|
|
type: type, |
|
|
|
type: type, |
|
|
|
); |
|
|
|
); |
|
|
|
if (result != null) { |
|
|
|
if (result != null) { |
|
|
|
for (final file in result.files) { |
|
|
|
for (final file in result.files) { |
|
|
|
bloc.uploadFile([...basePath, file.name], file.path!); |
|
|
|
await upload(File(file.path!)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future 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, |
|
|
|
|
|
|
|
AppLocalizations.of(context).filesConfirmUploadSizeWarning( |
|
|
|
|
|
|
|
filesize(sizeWarning), |
|
|
|
|
|
|
|
filesize(stat.size), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
))) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
widget.bloc.uploadFile([...widget.basePath, p.basename(file.path)], file.path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(final BuildContext context) => CustomDialog( |
|
|
|
Widget build(final BuildContext context) => CustomDialog( |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
@ -32,9 +56,11 @@ class FilesChooseCreateDialog extends StatelessWidget { |
|
|
|
), |
|
|
|
), |
|
|
|
title: Text(AppLocalizations.of(context).filesUploadFiles), |
|
|
|
title: Text(AppLocalizations.of(context).filesUploadFiles), |
|
|
|
onTap: () async { |
|
|
|
onTap: () async { |
|
|
|
Navigator.of(context).pop(); |
|
|
|
await uploadFromPick(FileType.any); |
|
|
|
|
|
|
|
|
|
|
|
await upload(FileType.any); |
|
|
|
if (mounted) { |
|
|
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
ListTile( |
|
|
|
ListTile( |
|
|
@ -44,9 +70,11 @@ class FilesChooseCreateDialog extends StatelessWidget { |
|
|
|
), |
|
|
|
), |
|
|
|
title: Text(AppLocalizations.of(context).filesUploadImages), |
|
|
|
title: Text(AppLocalizations.of(context).filesUploadImages), |
|
|
|
onTap: () async { |
|
|
|
onTap: () async { |
|
|
|
Navigator.of(context).pop(); |
|
|
|
await uploadFromPick(FileType.image); |
|
|
|
|
|
|
|
|
|
|
|
await upload(FileType.image); |
|
|
|
if (mounted) { |
|
|
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
if (Provider.of<HarbourPlatform>(context, listen: false).canUseCamera) ...[ |
|
|
|
if (Provider.of<HarbourPlatform>(context, listen: false).canUseCamera) ...[ |
|
|
@ -62,7 +90,7 @@ class FilesChooseCreateDialog extends StatelessWidget { |
|
|
|
final picker = ImagePicker(); |
|
|
|
final picker = ImagePicker(); |
|
|
|
final result = await picker.pickImage(source: ImageSource.camera); |
|
|
|
final result = await picker.pickImage(source: ImageSource.camera); |
|
|
|
if (result != null) { |
|
|
|
if (result != null) { |
|
|
|
bloc.uploadFile([...basePath, result.name], result.path); |
|
|
|
await upload(File(result.path)); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
@ -81,7 +109,7 @@ class FilesChooseCreateDialog extends StatelessWidget { |
|
|
|
builder: (final context) => const FilesCreateFolderDialog(), |
|
|
|
builder: (final context) => const FilesCreateFolderDialog(), |
|
|
|
); |
|
|
|
); |
|
|
|
if (result != null) { |
|
|
|
if (result != null) { |
|
|
|
bloc.browser.createFolder([...basePath, ...result]); |
|
|
|
widget.bloc.browser.createFolder([...widget.basePath, ...result]); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|