Skip to content

Commit

Permalink
設定のインポート・エクスポートでダイアログを閉じられるように
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Sep 27, 2023
1 parent ab36416 commit d83280b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
31 changes: 15 additions & 16 deletions lib/repository/import_export_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ class ImportExportRepository extends ChangeNotifier {
ImportExportRepository(this.reader);

Future<void> import(BuildContext context, Account account) async {
final folder = await showDialog<DriveFolder>(
barrierDismissible: false,
final result = await showDialog<FolderResult>(
context: context,
builder: (context2) => WillPopScope(
onWillPop: () async => false,
child: FolderSelectDialog(
account: account,
fileShowTarget: const ["miria.json", "miria.json.unknown"],
),
builder: (context2) => FolderSelectDialog(
account: account,
fileShowTarget: const ["miria.json", "miria.json.unknown"],
),
);
if (result == null) return;

final folder = result.folder;

Iterable<DriveFile> alreadyExists =
await reader(misskeyProvider(account)).drive.files.find(
Expand All @@ -53,6 +52,7 @@ class ImportExportRepository extends ChangeNotifier {
),
);

if (!context.mounted) return;
if (alreadyExists.isEmpty) {
await SimpleMessageDialog.show(context, "ここにMiriaの設定ファイルあれへんかったわ");
return;
Expand Down Expand Up @@ -121,17 +121,16 @@ class ImportExportRepository extends ChangeNotifier {
}

Future<void> export(BuildContext context, Account account) async {
final folder = await showDialog<DriveFolder>(
barrierDismissible: false,
final result = await showDialog<FolderResult>(
context: context,
builder: (context2) => WillPopScope(
onWillPop: () async => false,
child: FolderSelectDialog(
account: account,
fileShowTarget: const ["miria.json", "miria.json.unknown"],
),
builder: (context2) => FolderSelectDialog(
account: account,
fileShowTarget: const ["miria.json", "miria.json.unknown"],
),
);
if (result == null) return;

final folder = result.folder;

final alreadyExists =
await reader(misskeyProvider(account)).drive.files.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import 'package:miria/view/common/futable_list_builder.dart';
import 'package:miria/view/common/pushable_listview.dart';
import 'package:misskey_dart/misskey_dart.dart';

class FolderResult {
const FolderResult(this.folder);

final DriveFolder? folder;
}

class FolderSelectDialog extends ConsumerStatefulWidget {
final Account account;
final List<String>? fileShowTarget;
Expand Down Expand Up @@ -123,7 +129,7 @@ class FolderSelectDialogState extends ConsumerState<FolderSelectDialog> {
actions: [
ElevatedButton(
onPressed: () {
Navigator.of(context).pop(path.lastOrNull);
Navigator.of(context).pop(FolderResult(path.lastOrNull));
},
child: const Text("このフォルダーに保存する"),
)
Expand Down

0 comments on commit d83280b

Please sign in to comment.