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 7671e15 commit 1aabe1a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,7 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
],
);
} else if (result == DriveModalSheetReturnValue.upload) {
final result = await FilePicker.platform.pickFiles(
type: FileType.image,
allowMultiple: true,
);
final result = await FilePicker.platform.pickFiles(allowMultiple: true);
if (result == null || result.files.isEmpty) return;

final files = result.files.map((file) {
Expand Down
18 changes: 8 additions & 10 deletions lib/view/note_create_page/create_file_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:typed_data';

import 'package:auto_route/auto_route.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -9,8 +7,8 @@ import 'package:miria/model/misskey_post_file.dart';
import 'package:miria/providers.dart';
import 'package:miria/router/app_router.dart';
import 'package:miria/view/common/account_scope.dart';
import 'package:miria/view/common/misskey_notes/network_image.dart';
import 'package:miria/view/note_create_page/file_settings_dialog.dart';
import 'package:miria/view/note_create_page/thumbnail.dart';

class CreateFileView extends ConsumerWidget {
final int index;
Expand Down Expand Up @@ -71,29 +69,29 @@ class CreateFileView extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final type = file.type;
final isImage = file.type?.startsWith("image") ?? false;
return Column(
children: [
SizedBox(
height: 200,
child: GestureDetector(
onTap: (file.type?.startsWith("image") ?? false) &&
onTap: isImage &&
(defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.android)
? () => onTap(context, ref)
: null,
child: switch (file) {
PostFile(:final file) => Image.file(file),
AlreadyPostedFile(:final file) => NetworkImageView(
url: file.thumbnailUrl ?? file.url,
type: ImageType.imageThumbnail,
),
PostFile(:final file) =>
isImage ? Image.file(file) : Thumbnail(type: type),
AlreadyPostedFile(:final file) => Thumbnail.driveFile(file),
},
),
),
Row(
children: [
if (file.isNsfw) const Icon(Icons.details_rounded),
if (file.isNsfw) const Icon(Icons.warning_amber),
Text(file.fileName),
IconButton(
onPressed: () => detailTap(context, ref),
Expand Down
23 changes: 9 additions & 14 deletions lib/view/note_create_page/drive_file_select_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:miria/model/account.dart';
import 'package:miria/providers.dart';
import 'package:miria/view/common/misskey_notes/network_image.dart';
import 'package:miria/view/common/pushable_listview.dart';
import 'package:miria/view/note_create_page/thumbnail.dart';
import 'package:miria/view/themes/app_theme.dart';
import 'package:misskey_dart/misskey_dart.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -156,19 +156,14 @@ class DriveFileSelectDialogState extends ConsumerState<DriveFileSelectDialog> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: double.infinity,
height: 200,
child: item.thumbnailUrl == null
? const SizedBox.shrink()
: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: NetworkImageView(
fit: BoxFit.cover,
url: item.thumbnailUrl!,
type: ImageType.imageThumbnail,
),
),
ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Thumbnail.driveFile(
item,
width: double.infinity,
height: 200,
fit: BoxFit.cover,
),
),
Text(item.name),
],
Expand Down

0 comments on commit 1aabe1a

Please sign in to comment.