Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ final class Dependencies extends DependencyProvider {
});
registerLazySingleton<AuthTokenProvider>(() => get<AuthService>());
registerLazySingleton<DownloaderService>(DownloaderService.new);
registerLazySingleton<UploaderService>(UploaderService.new);
registerLazySingleton<CatalystCardano>(() => CatalystCardano.instance);
registerLazySingleton<RegistrationProgressNotifier>(
RegistrationProgressNotifier.new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract final class UploadSeedPhraseDialog {
return null;
}

final bytes = file.bytes;
final bytes = await file.readAsBytes();
final decodedText = utf8.decode(bytes);
final words = decodedText
.split(' ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ class _ImportProposalDialog {
allowedExtensions: [ProposalDocument.exportFileExt],
);

return file?.bytes;
return await file?.readAsBytes();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:catalyst_voices/dependency/dependencies.dart';
import 'package:catalyst_voices/widgets/buttons/voices_filled_button.dart';
import 'package:catalyst_voices/widgets/buttons/voices_outlined_button.dart';
import 'package:catalyst_voices/widgets/indicators/voices_linear_progress_indicator.dart';
Expand All @@ -6,14 +7,14 @@ import 'package:catalyst_voices/widgets/modals/voices_dialog.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:catalyst_voices_services/catalyst_voices_services.dart';
import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
import 'package:cross_file/cross_file.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dropzone/flutter_dropzone.dart';

typedef OnVoicesFileUploaded = Future<void> Function(VoicesFile value);
typedef OnVoicesFileUploaded = Future<void> Function(XFile value);

class VoicesUploadFileDialog extends StatefulWidget {
final String title;
Expand All @@ -34,7 +35,7 @@ class VoicesUploadFileDialog extends StatefulWidget {
@override
State<VoicesUploadFileDialog> createState() => _VoicesUploadFileDialogState();

static Future<VoicesFile?> show(
static Future<XFile?> show(
BuildContext context, {
required RouteSettings routeSettings,
required String title,
Expand All @@ -43,7 +44,7 @@ class VoicesUploadFileDialog extends StatefulWidget {
List<String>? allowedExtensions,
OnVoicesFileUploaded? onUpload,
}) {
return VoicesDialog.show<VoicesFile?>(
return VoicesDialog.show<XFile?>(
context: context,
routeSettings: routeSettings,
builder: (context) {
Expand All @@ -60,7 +61,7 @@ class VoicesUploadFileDialog extends StatefulWidget {
}

class _Buttons extends StatefulWidget {
final VoicesFile? selectedFile;
final XFile? selectedFile;
final OnVoicesFileUploaded? onUpload;

const _Buttons({
Expand Down Expand Up @@ -186,7 +187,7 @@ class _UploadContainer extends StatefulWidget {
final String itemNameToUpload;
final String? info;
final List<String>? allowedExtensions;
final ValueChanged<VoicesFile>? onFileSelected;
final ValueChanged<XFile>? onFileSelected;

const _UploadContainer({
required this.itemNameToUpload,
Expand Down Expand Up @@ -227,32 +228,21 @@ class _UploadContainerState extends State<_UploadContainer> {
final bytes = await _dropzoneController.getFileData(ev);
final name = await _dropzoneController.getFilename(ev);
widget.onFileSelected?.call(
VoicesFile(
XFile.fromData(
bytes,
name: name,
bytes: bytes,
),
);
},
),
InkWell(
onTap: () async {
final result = await FilePicker.platform.pickFiles(
type: (widget.allowedExtensions != null) ? FileType.custom : FileType.any,
allowedExtensions: (widget.allowedExtensions != null)
? widget.allowedExtensions!
: null,
final service = Dependencies.instance.get<UploaderService>();
final pickedFile = await service.uploadFile(
allowedExtensions: widget.allowedExtensions,
);
final file = result?.files.first;
final name = file?.name;
final bytes = file?.bytes;

if (name != null && bytes != null) {
widget.onFileSelected?.call(
VoicesFile(
name: name,
bytes: bytes,
),
);
if (pickedFile != null) {
widget.onFileSelected?.call(pickedFile);
}
},
child: Container(
Expand Down Expand Up @@ -317,7 +307,7 @@ class _UploadContainerState extends State<_UploadContainer> {
}

class _VoicesUploadFileDialogState extends State<VoicesUploadFileDialog> {
VoicesFile? _selectedFile;
XFile? _selectedFile;
bool _isUploading = false;

@override
Expand Down
1 change: 1 addition & 0 deletions catalyst_voices/apps/voices/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
catalyst_voices_view_models:
path: ../../packages/internal/catalyst_voices_view_models
collection: ^1.19.1
cross_file: ^0.3.4+2
device_info_plus: ^11.5.0
dotted_border: ^3.1.0
equatable: ^2.0.7
Expand Down
1 change: 1 addition & 0 deletions catalyst_voices/melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ command:
bloc_test: ^10.0.0
chopper: ^8.3.0
collection: ^1.19.1
cross_file: ^0.3.4+2
cryptography: ^2.7.0
device_info_plus: ^11.5.0
downloadsfolder: ^1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export 'document/validation/document_validator.dart';
export 'document/values/grouped_tags.dart';
export 'errors/errors.dart';
export 'errors/sync_exception.dart';
export 'file/voices_file.dart';
export 'info/app_info.dart';
export 'info/gateway_info.dart';
export 'info/system_info.dart';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export 'share/share_app_resource_url_resolver.dart';
export 'share/share_reviews_resource_url_resolver.dart';
export 'share/share_service.dart' show ShareService;
export 'sync/sync_manager.dart' show SyncManager;
export 'uploader/uploader_service.dart' show UploaderService;
export 'user/keychain_signer_service.dart' show KeychainSignerService;
export 'user/signer_service.dart';
export 'user/user_service.dart' show UserService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:catalyst_voices_services/src/downloader/utils/file_save_strategy.dart';
import 'package:downloadsfolder/downloadsfolder.dart';

/// Mixin that provides common file path helper methods for services
/// that need to work with download directories and file paths.
mixin FilePathHelperMixin {
/// Gets the download directory path if the strategy requires it.
/// Returns null for strategies that don't need a specific directory.
Future<String?> getDownloadPathIfNeeded(FileSaveStrategyType strategyType) async {
if (strategyType == FileSaveStrategyType.downloadsDirectory) {
final downloadDir = await getDownloadDirectory();
return downloadDir.path;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';
import 'dart:typed_data';

import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:catalyst_voices_services/src/common/file_path_helper_mixin.dart';
import 'package:catalyst_voices_services/src/downloader/utils/file_save_strategy.dart';
import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
import 'package:downloadsfolder/downloadsfolder.dart';
import 'package:path/path.dart' as p;

// ignore: one_member_abstracts
Expand All @@ -17,7 +17,7 @@ abstract interface class DownloaderService {
});
}

final class DownloaderServiceImpl implements DownloaderService {
final class DownloaderServiceImpl with FilePathHelperMixin implements DownloaderService {
const DownloaderServiceImpl();

@override
Expand Down Expand Up @@ -46,7 +46,7 @@ final class DownloaderServiceImpl implements DownloaderService {
final fileWithoutExtension = p.withoutExtension(filename);
final extensionName = p.extension(filename);

final downloadPath = await _getDownloadPathIfNeeded(strategyType);
final downloadPath = await getDownloadPathIfNeeded(strategyType);
final uniqueFilename = '$fileWithoutExtension$flavorName$extensionName';

return Uri.file(
Expand All @@ -55,14 +55,6 @@ final class DownloaderServiceImpl implements DownloaderService {
);
}

Future<String?> _getDownloadPathIfNeeded(FileSaveStrategyType strategyType) async {
if (strategyType == FileSaveStrategyType.downloadsDirectory) {
final downloadDir = await getDownloadDirectory();
return downloadDir.path;
}
return null;
}

String _getFlavorName(FileSaveStrategyType strategyType, AppEnvironmentType envType) {
if (strategyType == FileSaveStrategyType.filePicker) {
return envType.fileFlavorName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:catalyst_voices_services/src/common/file_path_helper_mixin.dart';
import 'package:catalyst_voices_services/src/downloader/utils/file_save_strategy.dart';
import 'package:cross_file/cross_file.dart';
import 'package:file_picker/file_picker.dart';

// ignore: one_member_abstracts
abstract interface class UploaderService {
const factory UploaderService() = UploaderServiceImpl;

Future<XFile?> uploadFile({
List<String>? allowedExtensions,
});
}

final class UploaderServiceImpl with FilePathHelperMixin implements UploaderService {
const UploaderServiceImpl();

@override
Future<XFile?> uploadFile({List<String>? allowedExtensions}) async {
final pickStrategy = FileSaveStrategyFactory.getDefaultStrategyType();
final initialDirectory = await getDownloadPathIfNeeded(pickStrategy);

final result = await FilePicker.platform.pickFiles(
withData: true,
type: allowedExtensions != null ? FileType.custom : FileType.any,
allowedExtensions: allowedExtensions,
initialDirectory: initialDirectory,
);
final file = result?.files.single;
final name = file?.name;
final bytes = file?.bytes;

if (name != null && bytes != null) {
return file?.xFile;
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
path: ../catalyst_voices_shared
cbor: 6.3.7
collection: ^1.19.1
cross_file: ^0.3.4+2
downloadsfolder: ^1.1.0
drift: ^2.28.1
equatable: ^2.0.7
Expand Down