build static method

List<Widget> build(
  1. BuildContext context
)

Returns the Widgets of this ChatSection.

Implementation

static List<Widget> build(BuildContext context) {
  final style = Theme.of(context).style;

  // Returns a [ChatMessage] built locally with the provided parameters.
  ChatItem message({
    bool fromMe = true,
    SendingStatus status = SendingStatus.sent,
    String? text = 'Lorem ipsum',
    List<String> attachments = const [],
    List<ChatItemQuote> repliesTo = const [],
  }) {
    final NativeFile image = NativeFile(
      name: 'Image',
      size: 2,
      bytes: CatImage.bytes,
      dimensions: CatImage.size,
    );

    return ChatMessage(
      ChatItemId.local(),
      ChatId.local(const UserId('me')),
      User(UserId(fromMe ? 'me' : '0'), UserNum('1234123412341234')),
      PreciseDateTime.now(),
      text: text == null ? null : ChatMessageText(text),
      attachments:
          attachments.map((e) {
            if (e == 'file') {
              return FileAttachment(
                id: AttachmentId.local(),
                original: PlainFile(relativeRef: '', size: 12300000),
                filename: 'Document.pdf',
              );
            } else {
              return LocalAttachment(image, status: SendingStatus.sent);
            }
          }).toList(),
      status: status,
      repliesTo: repliesTo,
    );
  }

  // Returns a [ChatInfo] built locally with the provided parameters.
  ChatItem info(ChatInfoAction action, {bool fromMe = true}) {
    return ChatInfo(
      ChatItemId.local(),
      ChatId.local(const UserId('me')),
      User(UserId(fromMe ? 'me' : '0'), UserNum('1234123412341234')),
      PreciseDateTime.now(),
      action: action,
    );
  }

  // Returns a [ChatCall] built locally with the provided parameters.
  ChatItem call({
    bool fromMe = true,
    bool withVideo = false,
    bool started = false,
    int? finishReasonIndex,
  }) {
    return ChatCall(
      const ChatItemId('dwd'),
      ChatId.local(const UserId('me')),
      User(UserId(fromMe ? 'me' : '0'), UserNum('1234123412341234')),
      PreciseDateTime.now(),
      withVideo: withVideo,
      members: [],
      conversationStartedAt:
          started
              ? PreciseDateTime.now().subtract(const Duration(hours: 1))
              : null,
      finishReasonIndex: finishReasonIndex,
      finishedAt: finishReasonIndex == null ? null : PreciseDateTime.now(),
    );
  }

  // Returns a [ChatItemWidget] with the provided [ChatItem].
  Widget chatItem(
    ChatItem v, {
    bool delivered = false,
    bool read = false,
    ChatKind kind = ChatKind.dialog,
  }) {
    return ChatItemWidget(
      item: Rx(v),
      chat: Rx(
        Chat(
          ChatId.local(const UserId('me')),
          kindIndex: kind.index,
          lastDelivery:
              delivered
                  ? null
                  : PreciseDateTime.fromMicrosecondsSinceEpoch(0),
          lastReads: [
            if (read)
              LastChatRead(
                const UserId('fqw'),
                PreciseDateTime(DateTime(15000)),
              ),
          ],
        ),
      ),
      me: const UserId('me'),
      reads: [
        if (read)
          LastChatRead(const UserId('fqw'), PreciseDateTime(DateTime(15000))),
      ],
    );
  }

  /// Returns a [ChatForwardWidget] with the provided [ChatItem]s as forwards.
  Widget chatForward(
    List<ChatItem> v, {
    ChatItem? note,
    bool delivered = false,
    bool read = false,
    bool fromMe = true,
    ChatKind kind = ChatKind.dialog,
  }) {
    return ChatForwardWidget(
      forwards: RxList(
        v
            .map(
              (e) => Rx(
                ChatForward(
                  e.id,
                  e.chatId,
                  e.author,
                  e.at,
                  quote: ChatItemQuote.from(e),
                ),
              ),
            )
            .toList(),
      ),
      authorId: fromMe ? const UserId('me') : const UserId('0'),
      note: Rx(note == null ? null : Rx(note)),
      chat: Rx(
        Chat(
          ChatId.local(const UserId('me')),
          kindIndex: kind.index,
          lastDelivery:
              delivered
                  ? null
                  : PreciseDateTime.fromMicrosecondsSinceEpoch(0),
          lastReads: [
            if (read)
              LastChatRead(
                const UserId('fqw'),
                PreciseDateTime(DateTime(15000)),
              ),
          ],
        ),
      ),
      me: const UserId('me'),
      reads: [
        if (read)
          LastChatRead(const UserId('fqw'), PreciseDateTime(DateTime(15000))),
      ],
    );
  }

  return [
    Headline(
      headline: 'TimeLabelWidget',
      background: style.colors.onBackgroundOpacity7,
      child: Column(
        children: [
          TimeLabelWidget(
            DateTime.now().subtract(const Duration(minutes: 10)),
          ),
          TimeLabelWidget(DateTime.now().subtract(const Duration(days: 1))),
          TimeLabelWidget(DateTime.now().subtract(const Duration(days: 7))),
          TimeLabelWidget(DateTime.now().subtract(const Duration(days: 64))),
          TimeLabelWidget(
            DateTime.now().subtract(const Duration(days: 365 * 4)),
          ),
        ],
      ),
    ),
    Headline(
      headline: 'UnreadLabel',
      background: style.colors.onBackgroundOpacity7,
      child: const Column(children: [UnreadLabel(123)]),
    ),
    Headline(
      headline: 'ChatItemWidget',
      padding: const EdgeInsets.fromLTRB(32, 8, 32, 0),
      background: style.colors.onBackgroundOpacity7,
      child: Column(
        children: [
          chatItem(
            message(
              status: SendingStatus.sending,
              text: 'Sending message...',
            ),
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(status: SendingStatus.error, text: 'Error'),
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(status: SendingStatus.sent, text: 'Sent message'),
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(status: SendingStatus.sent, text: 'Delivered message'),
            kind: ChatKind.dialog,
            delivered: true,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(status: SendingStatus.sent, text: 'Read message'),
            kind: ChatKind.dialog,
            read: true,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(
              status: SendingStatus.sent,
              text: 'Received message',
              fromMe: false,
            ),
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),

          // Replies.
          chatItem(
            message(
              status: SendingStatus.sent,
              text: 'Sent reply',
              fromMe: true,
              repliesTo: [
                ChatMessageQuote(
                  author: const UserId('me'),
                  at: PreciseDateTime.now(),
                  text: const ChatMessageText('Replied message'),
                ),
              ],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(
              status: SendingStatus.sent,
              text: 'Received reply',
              fromMe: false,
              repliesTo: [
                ChatMessageQuote(
                  author: const UserId('me'),
                  at: PreciseDateTime.now(),
                  text: const ChatMessageText('Replied message'),
                ),
              ],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),

          // Image attachments.
          chatItem(
            message(
              status: SendingStatus.sent,
              text: null,
              fromMe: true,
              attachments: ['image'],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(
              status: SendingStatus.sent,
              text: null,
              fromMe: false,
              attachments: ['image'],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),

          // File attachments.
          chatItem(
            message(
              status: SendingStatus.sent,
              text: 'Message with file attachment',
              fromMe: true,
              attachments: ['file'],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(
              status: SendingStatus.sent,
              text: null,
              fromMe: false,
              attachments: ['file'],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),

          // Images attachments.
          chatItem(
            message(
              status: SendingStatus.sent,
              fromMe: true,
              attachments: [
                'file',
                'file',
                'image',
                'image',
                'image',
                'image',
                'image',
              ],
              text: 'Message with file and image attachments',
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),
          chatItem(
            message(
              status: SendingStatus.sent,
              text: null,
              fromMe: false,
              attachments: ['file', 'file', 'image', 'image', 'image'],
            ),
            read: true,
            kind: ChatKind.dialog,
          ),
          const SizedBox(height: 8),

          // Info.
          const SizedBox(height: 8),
          chatItem(info(const ChatInfoActionCreated(null))),
          const SizedBox(height: 8),
          chatItem(
            info(
              ChatInfoActionMemberAdded(
                User(
                  const UserId('me'),
                  UserNum('1234123412341234'),
                  name: UserName('added'),
                ),
                null,
              ),
            ),
          ),
          const SizedBox(height: 8),
          chatItem(
            info(
              ChatInfoActionMemberAdded(
                User(
                  const UserId('me'),
                  UserNum('1234123412341234'),
                  name: UserName('User'),
                ),
                null,
              ),
              fromMe: false,
            ),
          ),
          const SizedBox(height: 8),

          // Call.
          chatItem(call(withVideo: true), read: true),
          const SizedBox(height: 8),
          chatItem(call(withVideo: true, fromMe: false), read: true),
          const SizedBox(height: 8),
          chatItem(call(started: true), read: true),
          const SizedBox(height: 8),
          chatItem(call(started: true, fromMe: false), read: true),
          const SizedBox(height: 8),
          chatItem(call(finishReasonIndex: 2, started: true), read: true),
          const SizedBox(height: 8),
          chatItem(
            call(finishReasonIndex: 2, started: true, fromMe: false),
            read: true,
          ),
          const SizedBox(height: 8),
        ],
      ),
    ),
    Headline(
      headline: 'ChatForwardWidget',
      padding: const EdgeInsets.fromLTRB(32, 8, 32, 0),
      background: style.colors.onBackgroundOpacity7,
      child: Column(
        children: [
          const SizedBox(height: 32),
          chatForward(
            [message(text: 'Forwarded message')],
            read: true,
            note: message(text: 'Comment'),
          ),
          const SizedBox(height: 8),
          chatForward(
            [message(text: 'Forwarded message')],
            read: true,
            fromMe: false,
            note: message(text: 'Comment'),
          ),
          const SizedBox(height: 32),
        ],
      ),
    ),
    Headline(
      headline: 'NotesBlock',
      background: style.colors.onBackgroundOpacity7,
      child: const Column(children: [NotesBlock()]),
    ),
  ];
}