[Flutter][Notion][備忘録] tableにhttpパッケージでPOSTして追加する

## 前提
- Notionのアカウント作成済
- Notionのインテグレーション利用可能済
- 追加したいテーブル作成済
- 追加したいテーブルのコネクト管理に自身のインテグレーション追加済

## 期待値
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3081664/99b39470-e263-983e-793a-28c1cb96f7a9.png)


## Notion APIのFlutterコードサンプル
```Dart
import 'package:flutter/material.dart';
import 'dart:convert';

import 'package:http/http.dart' as http;

class HttpWidget extends StatelessWidget {
  const HttpWidget({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO:
    return Scaffold(
      body: SafeArea(
        child: Center(
          child: Container(
            child: ElevatedButton(
              child: Text("http"),
              onPressed: (() async {
                Uri url = Uri.parse("https://api.notion.com/v1/pages");
                Map<String, String> headers = {
                  'content-type': 'application/json',
                  "Authorization":
                      "Bearer Notionのトークン",
                  "Notion-Version": "2022-06-28"
                };

                final postData = {
                  "parent": {"database_id": "NotionのテーブルID"},
                  "properties": {
                    "title": {
                      "title": [
                        {
                          "text": {
                            "content": "test",
                          },
                        },
                      ],
                    },
                    "contactType": {
                      "select": {"name": "hoge category"}
                    },
                    "status": {
                      "select": {"name": "open"}
                    },
                    "mailAddress": {
                      "rich_text": [
                        {
                          "text": {"content": "hoge@mail"}
                        }
                      ]
                    },
                    "userId": {
                      "rich_text": [
                        {
                          "text": {"content": "abcdefg"}
                        }
                      ]
                    }
                  },
                  "children": [
                    // {
                    //   "object": "block",
                    //   "type": "paragraph",
                    //   "paragraph": {
                    //     "rich_text": [
                    //       {
                    //         "type": "text",
                    //         "text": {"content": "hoge\n\nfoo"},
                    //       },
                    //     ],
                    //   },
                    // }
                    {
                      "type": "code",
                      "code": {
                        "rich_text": [
                          {
                            "type": "text",
                            "text": {"content": "hoge foo"}
                          }
                        ],
                        "language": "python"
                      }
                    }
                  ]
                };

                String body = jsonEncode(postData);

                http.Response resp =
                    await http.post(url, headers: headers, body: body);

                print(resp.body);
              }),
            ),
          ),
        ),
      ),
    );
  }
}

```

## GIT
https://github.com/lemon-solt/learning/blob/main/flutter/http_widget.dart

## 参考記事
[[Flutter] httpでAPIを呼び出す方法](https://dev-yakuza.posstree.com/flutter/http/)

[http | Dart Package](https://pub.dev/packages/http)

[DartでのJSONのエンコードとデコード - Qiita](https://qiita.com/akatsukaha/items/d2f9362ccadf72978773)

[Start building with the Notion API](https://developers.notion.com/reference/post-page)

[Start building with the Notion API](https://developers.notion.com/reference/block#code-blocks)