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

插件详情v1.2.0

notion_api

一个用于公开测试版 Notion API 的包装器,可像 Dart 的 Notion SDK 包一样进行管理。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
50
喜欢数
27
Pub 分数
140

安装插件

flutter pub add notion_api

插件介绍

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

一个 Dart 包,提供对公开测试版 Notion API 的封装,使开发者能够像使用原生 SDK 一样与 Notion 数据库、页面和内容进行交互。它通过为 Flutter 应用程序在多个平台上量身定制的直观方法,简化了身份验证、数据获取和操作。该包抽象了底层 HTTP 请求,提供了干净且类型安全的接口,用于处理 Notion 的结构化数据。非常适合需要与 Notion 工作区实现实时同步或动态内容管理的应用。

适合场景

  • 将 Notion 数据库集成到 Flutter 应用中
  • 同步应用数据与 Notion 页面
  • 使用 Notion 后端构建内容管理工具
  • 从Flutter应用自动更新Notion页面
  • 使用 Notion 作为数据源创建任务跟踪器

主要特点

  • 类型安全的 API 调用
  • 跨平台支持(Android、iOS、Web、macOS、Windows、Linux)
  • 通过 Notion API 令牌进行身份验证处理
  • 支持数据库查询和页面操作
  • 简单、可读的方法语法

适合对象

  • Flutter 开发人员构建生产力应用
  • 使用 Notion 作为主要工作区的团队
  • 需要与 Notion 进行双向同步的应用
  • 寻求轻量级 Notion 集成的开发者

使用建议

  • 需要有效的 Notion API 令牌
  • 仅限公开测试版 API 功能
  • 不适用于私人或企业专用的 Notion 端点
  • 随着 Notion API 的演进,可能需要更新
  • 无内置缓存或离线支持

原始 README

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

Notion API client for dart.

CI codecov

See the ROADMAP file to see what is coming next.

API implemented

Endpoint Avaliable Notes
Retrieve a database ✅
Query a database 🏗 Working on it
List databases ✅
Create a database ✅ Workin on more properties
Retrieve a page ✅
Create a page ✅ Workin on more properties
Update a page ✅ Workin on more properties
Retrieve block children ✅
Append block children ✅
Retrieve a user
List all users
Search

Usage

Important: The methods return a NotionResponse. You can find how to use it in its documentation.

NotionClient class

You only have to create a new instance of the NotionClient class and all the API requests will be available as class methods.

NotionClient notion = NotionClient(token: 'YOUR SECRET TOKEN FROM INTEGRATIONS PAGE');

Individual classes

You can also use individual request group class like NotionPagesClient or NotionDatabasesClient. They are used like the main client but the methods are class methods instead of class properties methods.

Example

// With main class
NotionClient notion = NotionClient(token: 'YOUR_TOKEN');
notion.databases.fetchAll();

// With individual class
NotionDatabasesClient databases = NotionDatabasesClient(token: 'YOUR_TOKEN');
databases.fetchAll();

A few examples

A page created and filled using only this package:
https://jonathangomz.notion.site/notion_api-example-0893dd2cb38a413d90165cb810b3c019

To see code to create the page above or see more examples go here.

Append blocks children
// Create children instance:
Children children = Children.withBlocks([
  Heading(text: Text('Test')),
  Paragraph(texts: [
    Text('Lorem ipsum (A)'),
    Text('Lorem ipsum (B)',
        annotations: TextAnnotations(
          bold: true,
          underline: true,
          color: ColorsTypes.Orange,
        ))
  ])
]);

// Send the instance to Notion
notion.blocks.append(
  to: 'YOUR_BLOCK_ID',
  children: children,
);
Create a page
// Create a page instance
Page page = Page(
  parent: Parent.database(id: 'YOUR_DATABASE_ID'),
  title: Text('NotionClient (v1): Page test'),
);

// Send the instance to Notion.
notion.pages.create(page);

Errors

Some errors that I have encounter and still don't know how to solve because are errors that also occur on Postman are:

Create page with chidren

When the parent is a page the error is:

"body failed validation: body.properties.title.type should be an array, instead was `\"array\"`."

But when the parent is a database then the error is:

"body failed validation: body.parent.page_id should be defined, instead was `undefined`."

You can create the page first and then add the children as shown in the examples.

Contributions

Please help, I don't even know if what I'm doing is right.

Rules

Some rules to follow:

  1. Please follow the dart convention format:
    1. Effective dart
    2. dart format
  2. If you are adding a new function, please also add the documentation.
  3. If you are adding a new parameters, please also add it to the current documentation.
  4. (Optional) Run the tests to know that everything is working just fine (See how run the tests).
    • This is optional because sometimes the tests fail on GitHub actions so anyway I will check this on my computer.

Tests

To be able to run the tests you will have to have a .env file on the root directory with the next variables:

  • TOKEN: The secret token.
  • TEST_DATABASE_ID: The database id where you will be working on.
  • TEST_PAGE_ID: Some page id inside the database specified above.
  • TEST_BLOCK_ID: Some block id inside the page specified above.
  • TEST_BLOCK_HEADING_ID: Some heading block id inside the page specified above.
Example:

The values are not valid of course.

TOKEN=secret_Oa24V8FbJ49JluJankVOQihyLiMXwqSQeeHuSFobQDW
TEST_DATABASE_ID=366da3d646bb458128071fdb2fbbf427
TEST_PAGE_ID=c3b53019-4470-443b-a141-95a3a1a44g60
TEST_BLOCK_ID=c8hac4bb32af48889228bf483d938e34
TEST_BLOCK_HEADING_ID=c8hac4bb32af48889228bf483d938e34

Next release

v1.2.1:

Release date: 02/Aug/2021

  • Add constructors with only single text content with default style for:
    • Paragraph.text('some text here...')
    • ToDo.text('some text here...', checked: true)
    • Heading.text('some text here...', type: 2)
    • BulletedListItem.text('some text here...')
    • NumberedListItem.text('some text here...')
    • Toggle.text('some text here...', children: [])
  • Add more constructors for Heading class:
    • one: Heading with type 1 by default.
    • two: Heading with type 2 by default.
    • three: Heading with type 3 by default.
  • Add more constructors for Text class:
    • code: Text with code style by default.
    • italic: Text with italic style by default.
    • bold: Text with bold style by default.
    • [Opt] list: List of words separated by comma (by default).
      • Example: Text.list() will receive a list of Text and will be concatenated separated with comma by default. It may be unnecessary. Can help to make the code more readable.
    • [Opt] sep: Text separator.
      • Example: Text.sep(), by default, will insert " " in a list of Text instances, but it will be able to do more things that I don't know yet, hehe. It may be unnecessary. Can help to make the code more readable.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。