xfile 1.1.0

Extend on dart File for more helpful functions.

Usage #

See the example.

import 'dart:io';

import 'package:xfile/xfile.dart';

main() {
  var path1 = "/root/fruit/apple/big-apple.png";

  XFile xFile;

  // many ways to get instance of XFile
  xFile = XFile(path1);
  xFile = XFile.fromPath(path1);
  xFile = XFile.fromDirectory(Directory("/root/animal"));
  xFile = XFile.fromUri(Uri.file(path1));
  xFile = XFile.fromFile(File(path1));
  xFile = XFile.parse(path1);
  xFile = XFile.concat("/root/animal", "fish/sushi.png");

  // many ways to append child
  xFile = XFile("/root"); // /root/
  xFile = xFile.append("animal"); // /root/animal/
  xFile = xFile + File("fish"); // /root/animal/fish/
  xFile = xFile + Directory("aaa"); // /root/animal/fish/aaa/
  xFile = xFile + "sushi.png"; // /root/animal/fish/aaa/sushi.png

  // cd back
  xFile = XFile.parse("/root/fruit/apple/big-apple.png");
  xFile.cdBack(); // /root/fruit/apple/
  xFile.cdBack(2); // /root/fruit/

  // transforms
  File file = xFile.toFile();
  file = xFile.file;
  Directory directory = xFile.toDirectory();
  directory = xFile.directory;
  Uri uri = xFile.toUri();
  uri = xFile.uri;

  var path2 = "C:/root/animal/fish/sushi.g.png";

  // get file information
  xFile = XFile(path2);
  xFile.scheme; // c
  xFile.fileName(); // sushi.g.png
  xFile.fileName(withExtension: false); // sushi.g
  xFile.pureFileName(); // sushi
  xFile.extension(); // png

  // XFile also implements all "File" and "Directory" methods,
  // all method name prefix or suffix "File" or "Directory" like this:
  xFile.existsFile();
  xFile.existsDirectory();

  xFile.renameFile("");
  xFile.renameDirectory("");

  xFile.deleteFile();
  xFile.deleteDirectory();

  xFile.fileParent;
  xFile.directoryParent;
}

1.0.0 #

  • Initial version, created by Stagehand

1.0.1 #

  • change name.

1.0.2 #

  • fix bugs

1.0.3 #

  • fix bug of extension()

1.0.4 #

  • support cdBack()

1.1.0 #

  • refactor and optimize, support more helpful functions and more easier to use

example/xfile_example.dart

import 'dart:io';

import 'package:xfile/xfile.dart';

main() {
  var path1 = "/root/fruit/apple/big-apple.png";

  XFile xFile;

  // many ways to get instance of XFile
  xFile = XFile(path1);
  xFile = XFile.fromPath(path1);
  xFile = XFile.fromDirectory(Directory("/root/animal"));
  xFile = XFile.fromUri(Uri.file(path1));
  xFile = XFile.fromFile(File(path1));
  xFile = XFile.parse(path1);
  xFile = XFile.concat("/root/animal", "fish/sushi.png");

  // many ways to append child
  xFile = XFile("/root"); // /root/
  xFile = xFile.append("animal"); // /root/animal/
  xFile = xFile + File("fish"); // /root/animal/fish/
  xFile = xFile + Directory("aaa"); // /root/animal/fish/aaa/
  xFile = xFile + "sushi.png"; // /root/animal/fish/aaa/sushi.png

  // cd back
  xFile = XFile.parse("/root/fruit/apple/big-apple.png");
  xFile.cdBack(); // /root/fruit/apple/
  xFile.cdBack(2); // /root/fruit/

  // transforms
  File file = xFile.toFile();
  file = xFile.file;
  Directory directory = xFile.toDirectory();
  directory = xFile.directory;
  Uri uri = xFile.toUri();
  uri = xFile.uri;

  var path2 = "C:/root/animal/fish/sushi.g.png";

  // get file information
  xFile = XFile(path2);
  xFile.scheme; // c
  xFile.fileName(); // sushi.g.png
  xFile.fileName(withExtension: false); // sushi.g
  xFile.pureFileName(); // sushi
  xFile.extension(); // png

  // XFile also implements all "File" and "Directory" methods,
  // all method name prefix or suffix "File" or "Directory" like this:
  xFile.existsFile();
  xFile.existsDirectory();

  xFile.renameFile("");
  xFile.renameDirectory("");

  xFile.deleteFile();
  xFile.deleteDirectory();

  xFile.fileParent;
  xFile.directoryParent;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  xfile: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:xfile/xfile.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Format lib/src/xfile_core.dart.

Run dartfmt to format lib/src/xfile_core.dart.

Format lib/xfile.dart.

Run dartfmt to format lib/xfile.dart.

Maintenance suggestions

The package description is too short. (-11 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0