nitori_message 0.0.1%2B2

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

Message Elements Builder and Parser for Nitori, A Dart/Flutter Implementation of Satori Protocol

A message builder for Nitori, provides several useful functions to construct or parse message elements of Satori Protocol.

Usage

Construct a message

import 'package:nitori_message/nitori_message.dart' as n;

var message = n.Message(
  children: [
    n.At(id: '001', name: 'Kawashiro Nitori'),
    n.Text('Hello, world!'),
    n.Image(src: 'https://example.com/image.png'),
    n.LineBreak(),
    n.Bold('Welcome to Nitori: '),
    n.Sharp(id: '001', name: 'Kawashiro Channel'),
  ],
); // n.Message

The code above will produce:

<message>
  <at id="001" name="Kawashiro Nitori" />
  Hello, world!
  <img src="https://example.com/image.png" />
  <br />
  <b>Welcome to Nitori: </b>
  <sharp id="001" name="Kawashiro Channel" />
</message>

You will notice there are some differences between the class names and the produced tags, this is because the class names are designed to be more readable and easy to use, while the tags are should be the same as those in Satori Protocol. You could see the Elements Cheat Sheet for more details.

Parse a message

import 'package:nitori_message/nitori_message.dart' as n;

var message = n.Message.parse(
  '<message>'
  '<at id="001" name="Kawashiro Nitori" />'
  'Hello, world!'
  '<img src="https://example.com/image.png" />'
  '<br />'
  '<b>Welcome to Nitori: </b>'
  '<sharp id="001" name="Kawashiro Channel" />'
  '</message>',
); // n.Message

The code above will produce a structure like this:

n.Message(
  children: [
    n.At(id: '001', name: 'Kawashiro Nitori'),
    n.Text('Hello, world!'),
    n.Image(src: 'https://example.com/image.png'),
    n.LineBreak(),
    n.Bold('Welcome to Nitori: '),
    n.Sharp(id: '001', name: 'Kawashiro Channel'),
  ],
); // n.Message

Since Nitori overrides the toString() method of each element, you could use print(message) to see the result.

print(message);

// =>
// <message>
//   <at id="001" name="Kawashiro Nitori" />
//   Hello, world!
//   <img src="https://example.com/image.png" />
//   <br />
//   <b>Welcome to Nitori: </b>
//   <sharp id="001" name="Kawashiro Channel" />
// </message>

Elements Cheat Sheet

Class NameSatori Element NameNote
Textplain textRepresent a text node.
At<at>
Sharp<sharp>
Anchor<a>
Image<img>
Audio<audio>
Video<video>
File<file>
Bold<b>
Idiomatic<i>
Underline<u>
Strikethrough<s>
Spoler<spl>
Code<code>
Superscript<sup>
Subscript<sub>
LineBreak<br>
Paragraph<p>
Message<message>
Quote<quote>
Author<author>
Button<button>Not implemented yet