搜索插件、代码仓与 APP 分类

插件详情v6.5.4

posix

在 OSx 和 Linux 上公开 POSIX API

AndroidiOSmacOSWindowsLinux
近 30 天下载
935万
喜欢数
12
Pub 分数
160

安装插件

flutter pub add posix

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

posix 包在 macOS 和 Linux 上提供对 POSIX 系统 API 的访问,支持文件操作、进程控制和信号处理等底层系统操作。该包专为需要与底层操作系统直接交互的桌面应用程序设计。通过 Dart 接口暴露原生 POSIX 函数,使其适用于高级系统编程任务。该包支持 macOS、Linux、Windows、Android 和 iOS 平台,但完整的 POSIX 功能主要在 macOS 和 Linux 上可用。该包非常适合需要对系统资源进行细粒度控制的开发者构建工具。

适合场景

  • 系统级文件操作
  • 进程和线程管理
  • 桌面应用程序中的信号处理
  • 跨平台系统实用工具
  • 底层操作系统交互

主要特点

  • 对原生 POSIX API 的访问
  • 对 macOS 和 Linux 的支持
  • 跨平台兼容性
  • Dart 友好的系统调用包装
  • 轻量且专注的设计

适合对象

  • 桌面应用程序开发者
  • 系统工具创建者
  • 高级 Flutter 用户
  • 需要操作系统级别访问权限的开发者
  • 需要进程隔离的工具

使用建议

  • 非POSIX平台上的功能受限
  • 需要平台特定知识
  • 不适用于移动应用核心逻辑
  • 可能需要提升权限
  • 最适合桌面环境

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Provides Dart access to the POSIX api for MacOS and Linux system.


import 'package:posix/posix.dart';

int uid = getuid();

Contributing

Dart types only

The api should only expose dart types. Any C types MUST be translated to dart types before being returned.

setters and getters

One of the first questsion is to whether we should use Dart's settings and getters:

e.g.


// getuid
int uid = getuid;

or

int uid = getuid();


/// setuid

uid = myuid;

or 

setuid = uid;

or

setuid(uid);

My initial thoughts is to make the api identical to the posix api which would mean that we don't use Dart setters and getters.

error returns

Do we return error no.s or do we throw.

As Dart is a modern language it uses Exception whereas posix returns error codes.

Often posix will return null and then expect you to make a separate call to 'errorno' to get the actual error no.

I'm inclined to bring the api that we expose into the modern world.

So I'm proposing that if an posix api returns an error that we throw a PosixException with a message and error code.

Adding additional functions

The process of adding additional functions is:

  1. Install ffigen
dart pub global activate ffigen
  1. Run the ffigen setup.

The paths may be different on your system. Search for clang-c/Index.h

sudo apt-get install libclang-dev
dart pub run ffigen:setup -I/usr/lib/llvm-11/include -L/usr/lib/llvm-11/lib
  1. find the required posix header file

  2. use ffigen to create the initial dart file from the header.

    • add your header file to ffigen.yaml
  3. Run ffigen

dart pub run ffigen  --config ffigen/linux.yaml 
  1. convert each method to take/return dart types.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目