ub3lal 3 nedēļas atpakaļ
revīzija
78ba38b9ba

+ 31 - 0
default_saver/.gitignore

@@ -0,0 +1,31 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.buildlog/
+.history
+.svn/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
+/pubspec.lock
+**/doc/api/
+.dart_tool/
+.flutter-plugins-dependencies
+/build/
+/coverage/

+ 10 - 0
default_saver/.metadata

@@ -0,0 +1,10 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled and should not be manually edited.
+
+version:
+  revision: "db50e20168db8fee486b9abf32fc912de3bc5b6a"
+  channel: "stable"
+
+project_type: package

+ 3 - 0
default_saver/CHANGELOG.md

@@ -0,0 +1,3 @@
+## 0.0.1
+
+* TODO: Describe initial release.

+ 1 - 0
default_saver/LICENSE

@@ -0,0 +1 @@
+TODO: Add your license here.

+ 39 - 0
default_saver/README.md

@@ -0,0 +1,39 @@
+<!--
+This README describes the package. If you publish this package to pub.dev,
+this README's contents appear on the landing page for your package.
+
+For information about how to write a good package README, see the guide for
+[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
+
+For general information about developing packages, see the Dart guide for
+[creating packages](https://dart.dev/guides/libraries/create-packages)
+and the Flutter guide for
+[developing packages and plugins](https://flutter.dev/to/develop-packages).
+-->
+
+TODO: Put a short description of the package here that helps potential users
+know whether this package might be useful for them.
+
+## Features
+
+TODO: List what your package can do. Maybe include images, gifs, or videos.
+
+## Getting started
+
+TODO: List prerequisites and provide or point to information on how to
+start using the package.
+
+## Usage
+
+TODO: Include short and useful examples for package users. Add longer examples
+to `/example` folder.
+
+```dart
+const like = 'sample';
+```
+
+## Additional information
+
+TODO: Tell users more about the package: where to find more information, how to
+contribute to the package, how to file issues, what response they can expect
+from the package authors, and more.

+ 4 - 0
default_saver/analysis_options.yaml

@@ -0,0 +1,4 @@
+include: package:flutter_lints/flutter.yaml
+
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options

+ 59 - 0
default_saver/lib/default_saver.dart

@@ -0,0 +1,59 @@
+import 'dart:io';
+import 'package:path_provider/path_provider.dart';
+import 'package:path/path.dart' as p;
+
+class DefaultSaver {
+  final Directory directory;
+
+  DefaultSaver._(this.directory);
+
+  static Future<DefaultSaver> init() async {
+    final dir = await getApplicationDocumentsDirectory();
+    return DefaultSaver._(dir);
+  }
+
+  /// Вспомогательный метод для сборки полного пути
+  String _buildPath(String key, String? extension) {
+    final fileName = extension != null ? '$key.$extension' : key;
+    return p.join(directory.path, fileName);
+  }
+
+  Future<void> saveFile({
+    required File file,
+    required String key,
+    String? extension,
+  }) async {
+    // Если расширение не передано, попробуем взять его из исходного файла
+    final ext = extension ?? p.extension(file.path).replaceFirst('.', '');
+    final String fullPath = _buildPath(key, ext);
+
+    await file.copy(fullPath);
+  }
+
+  /// 2. Получение файла (например, для Image.file(file))
+  File getFile(String key, {String? extension}) {
+    return File(_buildPath(key, extension));
+  }
+
+  /// 3. Проверка: существует ли файл?
+  Future<bool> exists(String key, {String? extension}) async {
+    return await File(_buildPath(key, extension)).exists();
+  }
+
+  /// Метод удаления файла
+  Future<bool> deleteFile({required String key, String? extension}) async {
+    try {
+      final String fullPath = _buildPath(key, extension);
+      final file = File(fullPath);
+
+      if (await file.exists()) {
+        await file.delete();
+        return true; // Файл успешно удален
+      }
+      return false; // Файл не найден
+    } catch (e) {
+      print('Ошибка при удалении файла: $e');
+      return false;
+    }
+  }
+}

+ 56 - 0
default_saver/pubspec.yaml

@@ -0,0 +1,56 @@
+name: default_saver
+description: "A new Flutter package project."
+version: 0.0.1
+homepage:
+
+environment:
+  sdk: ^3.11.4
+  flutter: ">=1.17.0"
+
+dependencies:
+  flutter:
+    sdk: flutter
+  path: ^1.9.1
+  path_provider: ^2.1.5
+
+dev_dependencies:
+  flutter_test:
+    sdk: flutter
+  flutter_lints: ^6.0.0
+
+# For information on the generic Dart part of this file, see the
+# following page: https://dart.dev/tools/pub/pubspec
+
+# The following section is specific to Flutter packages.
+flutter:
+
+  # To add assets to your package, add an assets section, like this:
+  # assets:
+  #   - images/a_dot_burr.jpeg
+  #   - images/a_dot_ham.jpeg
+  #
+  # For details regarding assets in packages, see
+  # https://flutter.dev/to/asset-from-package
+  #
+  # An image asset can refer to one or more resolution-specific "variants", see
+  # https://flutter.dev/to/resolution-aware-images
+
+  # To add custom fonts to your package, add a fonts section here,
+  # in this "flutter" section. Each entry in this list should have a
+  # "family" key with the font family name, and a "fonts" key with a
+  # list giving the asset and other descriptors for the font. For
+  # example:
+  # fonts:
+  #   - family: Schyler
+  #     fonts:
+  #       - asset: fonts/Schyler-Regular.ttf
+  #       - asset: fonts/Schyler-Italic.ttf
+  #         style: italic
+  #   - family: Trajan Pro
+  #     fonts:
+  #       - asset: fonts/TrajanPro.ttf
+  #       - asset: fonts/TrajanPro_Bold.ttf
+  #         weight: 700
+  #
+  # For details regarding fonts in packages, see
+  # https://flutter.dev/to/font-from-package

+ 5 - 0
default_saver/test/default_saver_test.dart

@@ -0,0 +1,5 @@
+import 'package:flutter_test/flutter_test.dart';
+
+import 'package:default_saver/default_saver.dart';
+
+void main() {}