mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-24 17:31:06 +08:00
RenameDialog: Move logic to Repo class
I want all the domain logic to be in the Repo class, this way it can be performed over another thread / connection. Also, it's far easier to test this way.
This commit is contained in:
@ -914,6 +914,13 @@ class GitJournalRepo with ChangeNotifier {
|
||||
|
||||
return Result(null);
|
||||
}
|
||||
|
||||
Result<bool> fileExists(String path) {
|
||||
return catchAllSync(() {
|
||||
var type = io.FileSystemEntity.typeSync(path);
|
||||
return Result(type != io.FileSystemEntityType.notFound);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _copyDirectory(String source, String destination) async {
|
||||
|
@ -9,9 +9,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path/path.dart';
|
||||
import 'package:universal_io/io.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:gitjournal/generated/locale_keys.g.dart';
|
||||
import 'package:gitjournal/repository.dart';
|
||||
|
||||
class RenameDialog extends StatefulWidget {
|
||||
final String oldPath;
|
||||
@ -87,8 +88,14 @@ class _RenameDialogState extends State<RenameDialog> {
|
||||
});
|
||||
|
||||
var newPath = join(dirname(widget.oldPath), value);
|
||||
if (FileSystemEntity.typeSync(newPath) !=
|
||||
FileSystemEntityType.notFound) {
|
||||
var repo = context.read<GitJournalRepo>();
|
||||
var r = repo.fileExists(newPath);
|
||||
if (r.isFailure) {
|
||||
return r.error.toString();
|
||||
}
|
||||
var exists = r.getOrThrow();
|
||||
|
||||
if (exists) {
|
||||
return tr(LocaleKeys.widgets_rename_validator_exists);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user