aboutsummaryrefslogtreecommitdiff
path: root/frontend/lib/views/chat/user_message_tile.dart
blob: a707a6e53a5ccf3f82fd9f663f029893b81fb373 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import 'package:flutter/material.dart';

class UserMessageTile extends StatelessWidget {
  final String message;

  // Constructor takes the user message as a required parameter
  const UserMessageTile({
    Key? key,
    required this.message,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        // Calculate the width of the chat view based on the constraints provided
        double chatViewWidth = constraints.maxWidth;

        // Determine the width of the message tile based on the chat view width
        double tileWidth = (chatViewWidth >= 1000) ? 900 : chatViewWidth - 40;

        return Align(
          alignment: Alignment.center,
          child: Container(
            width: tileWidth,
            // Minimum height constraint for the container
            constraints: const BoxConstraints(
              minHeight: 50,
            ),
            // Margin and padding for styling
            margin: const EdgeInsets.symmetric(vertical: 8),
            padding: const EdgeInsets.symmetric(horizontal: 20),
            // Decoration to style the container with a white background, thin black border, and small corner radius
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(color: Colors.black, width: 0.5),
              borderRadius: BorderRadius.circular(4),
            ),
            child: Row(
              children: [
                // "User" label with custom styling
                const Text(
                  "User",
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(width: 20),
                // Expanded widget to accommodate the message text
                Expanded(
                  child: Container(
                    // Padding for the text content
                    padding: const EdgeInsets.fromLTRB(0, 10, 20, 10),
                    // Displaying the user message with no max line limit
                    child: Text(
                      message,
                      maxLines: null,
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}