Skip to content

Commit

Permalink
メディアをアップロードできるように
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Apr 20, 2024
1 parent f5ccd94 commit bf5faef
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
3 changes: 2 additions & 1 deletion lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@
}
},
"chooseFile": "ファイルを選択",
"uploadFile": "アップロード",
"uploadMedia": "メディアをアップロード",
"uploadFile": "ファイルをアップロード",
"fromDrive": "ドライブから",
"fileName": "ファイル名",
"randomizeFileName": "ファイル名をランダムにする",
Expand Down
80 changes: 45 additions & 35 deletions lib/state_notifier/note_create_page/note_create_state_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,44 +455,54 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
final result = await showModalBottomSheet<DriveModalSheetReturnValue?>(
context: context, builder: (context) => const DriveModalSheet());

if (result == DriveModalSheetReturnValue.drive) {
if (!mounted) return;
final result = await showDialog<List<DriveFile>?>(
context: context,
builder: (context) => DriveFileSelectDialog(
account: state.account,
allowMultiple: true,
),
);
if (result == null || result.isEmpty) return;
switch (result) {
case DriveModalSheetReturnValue.drive:
if (!context.mounted) return;
final result = await showDialog<List<DriveFile>?>(
context: context,
builder: (context) => DriveFileSelectDialog(
account: state.account,
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);
if (result == null || result.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;
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,
);
if (pickerResult == null || pickerResult.files.isEmpty) return;

if (!mounted) return;
state = state.copyWith(
files: [
...state.files,
...files,
],
);
final files = pickerResult.files.map(
(file) {
final path = file.path;
if (path != null) {
return PostFile.file(fileSystem.file(path));
}
return null;
},
).nonNulls;

if (!mounted) return;
state = state.copyWith(
files: [
...state.files,
...files,
],
);
default:
}
}

Expand Down
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
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

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

class DriveModalSheet extends StatelessWidget {
const DriveModalSheet({super.key});
Expand All @@ -11,10 +11,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: () {
Navigator.of(context).pop(DriveModalSheetReturnValue.upload);
Navigator.of(context).pop(DriveModalSheetReturnValue.uploadMedia);
},
),
ListTile(
title: Text(S.of(context).uploadFile),
leading: const Icon(Icons.upload_file),
onTap: () {
Navigator.of(context).pop(DriveModalSheetReturnValue.uploadFile);
},
),
ListTile(
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 @@ -2235,7 +2235,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 @@ -2296,7 +2296,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 bf5faef

Please sign in to comment.