Skip to content

Commit

Permalink
メディアをアップロードできるように
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Nov 13, 2024
1 parent 3dd5159 commit 5152702
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
3 changes: 2 additions & 1 deletion lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@
}
},
"chooseFile": "ファイルを選択",
"uploadFile": "アップロード",
"uploadMedia": "メディアをアップロード",
"uploadFile": "ファイルをアップロード",
"fromDrive": "ドライブから",
"fileName": "ファイル名",
"randomizeFileName": "ファイル名をランダムにする",
Expand Down
68 changes: 38 additions & 30 deletions lib/state_notifier/note_create_page/note_create_state_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -488,40 +488,48 @@ class NoteCreateNotifier extends _$NoteCreateNotifier {
.read(appRouterProvider)
.push<DriveModalSheetReturnValue>(const DriveModalRoute());

if (result == DriveModalSheetReturnValue.drive) {
final result = await ref.read(appRouterProvider).push<List<DriveFile>>(
DriveFileSelectRoute(
account: ref.read(accountContextProvider).postAccount,
allowMultiple: true,
),
);
if (result == null || result.isEmpty) return;
switch (result) {
case DriveModalSheetReturnValue.drive:
final result = await ref.read(appRouterProvider).push<List<DriveFile>>(
DriveFileSelectRoute(
account: ref.read(accountContextProvider).postAccount,
allowMultiple: true,
),
);
if (result == null || result.isEmpty) return;

final files = result.map((file) => AlreadyPostedFile.file(file));
final files = result.map((file) => AlreadyPostedFile.file(file));

state = state.copyWith(
files: [
...state.files,
...files,
],
);
} else if (result == DriveModalSheetReturnValue.upload) {
final result = await FilePicker.platform.pickFiles(
allowMultiple: true,
allowCompression: Platform.isIOS, // v8.1.3ではiOS以外でこの値を使用していない
compressionQuality: 0, // Androidでは0にすることで圧縮パススルー
);
if (result == null || result.files.isEmpty) return;
state = state.copyWith(
files: [
...state.files,
...files,
],
);
case DriveModalSheetReturnValue.uploadFile ||
DriveModalSheetReturnValue.uploadMedia:
final pickerResult = await FilePicker.platform.pickFiles(
type: result == DriveModalSheetReturnValue.uploadMedia
? FileType.media
: FileType.any,
allowMultiple: true,
allowCompression: Platform.isIOS, // v8.1.3ではiOS以外でこの値を使用していない
compressionQuality: 0, // Androidでは0にすることで圧縮パススルー
);
if (pickerResult == null || pickerResult.files.isEmpty) return;

final files = result.files.map((file) {
final path = file.path;
if (path != null) {
return PostFile.file(_fileSystem.file(path));
}
return null;
}).nonNulls;
final files = pickerResult.files.map(
(file) {
final path = file.path;
if (path != null) {
return PostFile.file(_fileSystem.file(path));
}
return null;
},
).nonNulls;

state = state.copyWith(files: [...state.files, ...files]);
state = state.copyWith(files: [...state.files, ...files]);
default:
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions lib/view/note_create_page/drive_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "package:auto_route/auto_route.dart";
import "package:flutter/material.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";

enum DriveModalSheetReturnValue { upload, drive }
enum DriveModalSheetReturnValue { uploadMedia, uploadFile, drive }

@RoutePage<DriveModalSheetReturnValue>()
class DriveModalSheet extends StatelessWidget {
Expand All @@ -13,10 +13,17 @@ class DriveModalSheet extends StatelessWidget {
return ListView(
children: [
ListTile(
title: Text(S.of(context).uploadFile),
title: Text(S.of(context).uploadMedia),
leading: const Icon(Icons.upload),
onTap: () async =>
context.maybePop(DriveModalSheetReturnValue.upload),
context.maybePop(DriveModalSheetReturnValue.uploadMedia),
),
ListTile(
title: Text(S.of(context).uploadFile),
leading: const Icon(Icons.upload_file),
onTap: () {
Navigator.of(context).pop(DriveModalSheetReturnValue.uploadFile);
},
),
ListTile(
title: Text(S.of(context).fromDrive),
Expand Down
4 changes: 2 additions & 2 deletions test/view/note_create_page/note_create_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3014,7 +3014,7 @@ void main() {
await tester.tap(find.byIcon(Icons.image));
await tester.pumpAndSettle();

await tester.tap(find.text("アップロード"));
await tester.tap(find.text("ファイルをアップロード"));
await tester.pumpAndSettle();

await tester.enterText(
Expand Down Expand Up @@ -3102,7 +3102,7 @@ void main() {
await tester.tap(find.byIcon(Icons.image));
await tester.pumpAndSettle();

await tester.tap(find.text("アップロード"));
await tester.tap(find.text("ファイルをアップロード"));
await tester.pumpAndSettle();

await tester.enterText(
Expand Down

0 comments on commit 5152702

Please sign in to comment.