// ignore_for_file: non_constant_identifier_names

import 'dart:async';
import 'dart:math';
// import 'dart:js' as js;
// import 'dart:html' as html;
import 'package:fis_i18n/i18n.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';

/// 此页面是死的页面，暂时用作展示使用
///
class OverdueUrgeReplyPage extends StatefulWidget implements FWidget {
  final String? orderNo;

  OverdueUrgeReplyPage({
    Key? key,
    this.orderNo = '11',
  }) : super(key: key);

  _OverdueUrgeReplyPageState createState() => _OverdueUrgeReplyPageState();
}

class _OverdueUrgeReplyPageState extends State<OverdueUrgeReplyPage> {
  TextEditingController? textEditingController;
  ScrollController _scrollController = ScrollController(); //listview的控制器
  double? contentMaxWidth;
  String? userId;
  String? employeeNo = '11';
  String? userName;

  @override
  void initState() {
    super.initState();
    textEditingController = TextEditingController();
    initData();
    // 在 Flutter 页面中嵌入一个图像元素，用于接收拖拽事件
    // 创建一个带加号的实心边框的 div 元素
    // final myImage = html.DivElement()
    //   ..className = 'file-uploader'
    //   ..text = '+';
    // html.document.body?.append(myImage);
    // myImage.style
    //   ..position = 'fixed'
    //   ..bottom = '0'
    //   ..height = '100px'
    //   ..width = '100%'
    //   ..margin = '0 10 0 30'
    //   ..lineHeight = '94px'
    //   ..fontSize = '3rem'
    //   ..color = 'black'
    //   ..textAlign = 'center'
    //   ..border = '2px solid #D3D3D3'
    //   ..zIndex = '9999';
    // // 监听拖拽事件
    // myImage.onDragOver.listen((event) {
    //   event.preventDefault();
    //   event.stopPropagation();

    //   myImage.style.border = '2px dashed blue';
    // });

    // myImage.onDragLeave.listen((event) {
    //   event.preventDefault();
    //   event.stopPropagation();
    //   myImage.style.border = '2px solid #D3D3D3';
    // });

    // myImage.onDrop.listen((event) async {
    //   event.preventDefault();
    //   event.stopPropagation();
    //   myImage.style.border = '2px solid #D3D3D3';

    //   final fileList = event.dataTransfer.files;
    //   if (fileList?.isEmpty ?? true) {
    //     return;
    //   }
    //   print(event.dataTransfer.files![0]);

    //   // 接收到文件，把它发送到服务器端
    //   final formData = html.FormData();
    //   formData.appendBlob('file', fileList![0]);
    //   list.add(
    //     {
    //       "createdAt": 'time',
    //       "cusUid": '1',
    //       "employeeNo": '11',
    //       "name": 'God',
    //       "orderNo": '1',
    //       "reply":
    //           'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
    //       "updatedAt": 'time',
    //       "isImage": true,
    //       'status': SUCCESSED_TYPE,
    //       'tag': '1',
    //     },
    //   );
    //   // await js.context
    //   //     .callMethod('uploadFile', ['http://your-server.com/upload', formData]);
    // });
  }

  initData() async {
    setState(() {
      list = [
        // {
        //   "createdAt": 'time',
        //   "cusUid": '1',
        //   "employeeNo": '1',
        //   "name": '飞飞',
        //   "orderNo": '1',
        //   "reply":
        //       '这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的这是一段测试的',
        //   "updatedAt": 'time',
        //   'status': SENDING_TYPE,
        //   'tag': '1',
        // },
        {
          "createdAt": 'time',
          "cusUid": '1',
          "employeeNo": '11',
          "name": 'God',
          "orderNo": '1',
          "reply":
              'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
          "updatedAt": 'time',
          "isImage": true,
          'status': SENDING_TYPE,
          'tag': '1',
        },
        {
          "createdAt": 'time',
          "cusUid": '1',
          "employeeNo": '1',
          "name": '飞飞',
          "orderNo": '1',
          "reply":
              'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
          "updatedAt": 'time',
          'status': SUCCESSED_TYPE,
          'tag': '1',
        },
        {
          "createdAt": 'time',
          "cusUid": '1',
          "employeeNo": '11',
          "name": 'God',
          "orderNo": '1',
          "reply": '刚刚图片的地址是啥',
          "updatedAt": 'time',
          "isImage": false,
          'status': SUCCESSED_TYPE,
          'tag': '1',
        },
        {
          "createdAt": 'time',
          "cusUid": '1',
          "employeeNo": '1',
          "name": '飞飞',
          "orderNo": '1',
          "reply":
              'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
          "isImageAnalysis": true,
          "updatedAt": 'time',
          'status': SUCCESSED_TYPE,
          'tag': '1',
        },
        {
          "createdAt": 'time',
          "cusUid": '1',
          "employeeNo": '11',
          "name": 'God',
          "orderNo": '1',
          "reply":
              'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
          "updatedAt": 'time',
          "isImage": true,
          'status': SUCCESSED_TYPE,
          'tag': '1',
        },
      ];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(
          child: Container(
            constraints: BoxConstraints(
              maxWidth: 1200, // 设置最大宽度为 1200
            ),
            margin: EdgeInsets.all(15),
            // height: double.infinity,
            decoration: BoxDecoration(
              color: Color(0xFFF1F5FB),
              border: Border.all(
                color: FTheme.ins.colorScheme.line,
              ),
              borderRadius: BorderRadius.all(
                Radius.circular(8),
              ),
            ),
            child: Column(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Container(
                    //列表内容少的时候靠上
                    alignment: Alignment.topCenter,
                    child: _renderList(),
                  ),
                ),
                Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    boxShadow: [
                      BoxShadow(
                        color: Color(0x14000000),
                        blurRadius: 10,
                      ),
                    ],
                    borderRadius: BorderRadius.all(
                      Radius.circular(8),
                    ),
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      // Row(
                      //   crossAxisAlignment: CrossAxisAlignment.end,
                      //   children: <Widget>[
                      //     Expanded(
                      //       child: Container(
                      //         margin: EdgeInsets.fromLTRB(15, 10, 0, 10),
                      //         constraints: BoxConstraints(
                      //           maxHeight: 100.0,
                      //           minHeight: 50.0,
                      //         ),
                      //         decoration: BoxDecoration(
                      //             color: Color(0xFFF5F6FF),
                      //             borderRadius: BorderRadius.all(Radius.circular(2))),
                      //         child: TextField(
                      //           controller: textEditingController,
                      //           cursorColor: Color(0xFF464EB5),
                      //           maxLines: null,
                      //           maxLength: 200,
                      //           decoration: InputDecoration(
                      //             counterText: '',
                      //             border: InputBorder.none,
                      //             contentPadding: EdgeInsets.only(
                      //                 left: 16.0,
                      //                 right: 16.0,
                      //                 top: 10.0,
                      //                 bottom: 10.0),
                      //             hintText: "回复",
                      //             hintStyle: TextStyle(
                      //                 color: Color(0xFFADB3BA), fontSize: 15),
                      //           ),
                      //           style:
                      //               TextStyle(color: Color(0xFF03073C), fontSize: 15),
                      //         ),
                      //       ),
                      //     ),
                      //     GestureDetector(
                      //       behavior: HitTestBehavior.opaque,
                      //       child: Container(
                      //         padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
                      //         alignment: Alignment.center,
                      //         height: 70,
                      //         child: Text(
                      //           '发送',
                      //           style: TextStyle(
                      //             color: Colors.blue,
                      //             fontSize: 14,
                      //           ),
                      //         ),
                      //       ),
                      //       onTap: () {
                      //         sendTxt();
                      //       },
                      //     ),
                      //   ],
                      // ),
                      Row(
                        children: [
                          FExpanded(
                            child: FContainer(
                              height: 150,
                              margin: EdgeInsets.only(
                                  left: 15, right: 15, bottom: 15, top: 15),
                              decoration: BoxDecoration(
                                border: Border.all(
                                  color: FTheme.ins.colorScheme.line,
                                  width: 0.5,
                                ),
                                borderRadius: BorderRadius.all(
                                  Radius.circular(
                                    8,
                                  ),
                                ),
                              ),
                              child: FColumn(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  FIcon(
                                    Icons.add,
                                    size: 50,
                                    color: FTheme.ins.colorScheme.primary,
                                  ),
                                  FText(
                                    i18nBook.laboratory
                                        .dragAndDropUltrasoundImages.t,
                                    style: TextStyle(
                                      color: FTheme.ins.colorScheme.primary,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                          //               ElevatedButton(
                          //   businessParent: this,
                          //   onPressed: isDisabled ? null : onBtnTap,
                          //   name: text,
                          //   child: FText(
                          //     text,
                          //     style: textStyle,
                          //   ),
                          //   style: btnStyle,
                          // );
                        ],
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  List list = []; //列表要展示的数据

  _renderList() {
    return GestureDetector(
      child: Scrollbar(
        // isAlwaysShown: true,
        child: ListView.builder(
          reverse: true,
          shrinkWrap: true,
          padding: EdgeInsets.only(top: 27),
          itemBuilder: (context, index) {
            var item = list[index];
            return GestureDetector(
              child: item['employeeNo'] == employeeNo
                  ? _renderRowSendByMe(context, item)
                  : _renderRowSendByOthers(context, item),
              onTap: () {},
            );
          },
          itemCount: list.length,
          physics: const AlwaysScrollableScrollPhysics(),
          controller: _scrollController,
        ),
      ),
      onTap: () {
        FocusScope.of(context).requestFocus(FocusNode());
      },
    );
  }

  Widget _renderRowSendByOthers(BuildContext context, item) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, 0, 0, 20),
      child: Column(
        children: <Widget>[
          Padding(
            child: Text(
              '2023-4-26 15:22',
              textAlign: TextAlign.center,
              style: TextStyle(
                color: Color(0xFFA1A6BB),
                fontSize: 14,
              ),
            ),
            padding: EdgeInsets.only(bottom: 20),
          ),
          Padding(
            padding: EdgeInsets.only(left: 15, right: 45),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  alignment: Alignment.center,
                  width: 30,
                  height: 30,
                  decoration: BoxDecoration(
                      color: Color(0xFF464EB5),
                      borderRadius: BorderRadius.all(Radius.circular(15))),
                  child: Padding(
                    child: Text(
                      item['name'].toString().substring(0, 1),
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 14,
                      ),
                    ),
                    padding: EdgeInsets.only(bottom: 2),
                  ),
                ),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Padding(
                        child: Text(
                          item['name'] ?? '测试',
                          softWrap: true,
                          style: TextStyle(
                            color: Color(0xFF677092),
                            fontSize: 14,
                          ),
                        ),
                        padding: EdgeInsets.only(left: 20, right: 30),
                      ),
                      Stack(
                        children: <Widget>[
                          // Container(
                          //   child: Image(
                          //       width: 11,
                          //       height: 20,
                          //       image: AssetImage("assets/images/john.jpg")),
                          //   margin: EdgeInsets.fromLTRB(2, 16, 0, 0),
                          // ),
                          Container(
                            decoration: BoxDecoration(
                              boxShadow: [
                                BoxShadow(
                                  offset: Offset(4.0, 7.0),
                                  color: Color(0x04000000),
                                  blurRadius: 10,
                                ),
                              ],
                              color: Colors.white,
                              borderRadius: BorderRadius.all(
                                Radius.circular(10),
                              ),
                            ),
                            margin: EdgeInsets.only(top: 8, left: 10),
                            padding: EdgeInsets.all(10),
                            child: item['isImageAnalysis'] ?? false
                                ? Container(
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      mainAxisSize: MainAxisSize.min,
                                      children: [
                                        Image(
                                          height: 100,
                                          image: NetworkImage(
                                            item['reply'] ??
                                                'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
                                          ),
                                        ),
                                        Divider(),
                                        Container(
                                          padding: EdgeInsets.symmetric(
                                              horizontal: 15),
                                          child: i18nBook.isCurrentChinese
                                              ? Column(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.start,
                                                  children: [
                                                    Text('【诊断结果】'),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('疾病标签:'),
                                                        ),
                                                        Text('肝血管瘤'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('病灶大小:'),
                                                        ),
                                                        Text('1.43cm x 1.85cm'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('可能性:'),
                                                        ),
                                                        Text('50%'),
                                                      ],
                                                    ),
                                                    Text('【特征】'),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('形状:'),
                                                        ),
                                                        Text('椭圆形'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('生长方向:'),
                                                        ),
                                                        Text('平行'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('回声类型:'),
                                                        ),
                                                        Text('无回声'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('病灶边界:'),
                                                        ),
                                                        Text('清晰'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('边缘:'),
                                                        ),
                                                        Text('光整'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 100,
                                                          child: Text('纵横比:'),
                                                        ),
                                                        Text('>1'),
                                                      ],
                                                    ),
                                                  ],
                                                )
                                              : Column(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.start,
                                                  children: [
                                                    Text(
                                                        '【Diagnostic Results】'),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Disease Label:'),
                                                        ),
                                                        Text(
                                                            'Liver Hemangioma'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Lesion Size:'),
                                                        ),
                                                        Text('1.43cm x 1.85cm'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Probability:'),
                                                        ),
                                                        Text('50%'),
                                                      ],
                                                    ),
                                                    Text('【Features】'),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text('Shape:'),
                                                        ),
                                                        Text('Elliptical'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Growth Orientation:'),
                                                        ),
                                                        Text('Parallel'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Echo Type:'),
                                                        ),
                                                        Text('No Echo'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Lesion Boundary:'),
                                                        ),
                                                        Text('Clear'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text('Edge:'),
                                                        ),
                                                        Text('Smooth'),
                                                      ],
                                                    ),
                                                    Row(
                                                      children: [
                                                        Container(
                                                          width: 150,
                                                          child: Text(
                                                              'Aspect Ratio:'),
                                                        ),
                                                        Text('>1'),
                                                      ],
                                                    ),
                                                  ],
                                                ),
                                        ),
                                      ],
                                    ),
                                  )
                                : Text(
                                    item['reply'],
                                    style: TextStyle(
                                      color: Color(0xFF03073C),
                                      fontSize: 15,
                                    ),
                                  ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _renderRowSendByMe(BuildContext context, item) {
    return Container(
      padding: EdgeInsets.fromLTRB(0, 0, 0, 20),
      child: Column(
        children: <Widget>[
          Padding(
            child: Text(
              '2023-4-26 15:22',
              textAlign: TextAlign.center,
              style: TextStyle(
                color: Color(0xFFA1A6BB),
                fontSize: 14,
              ),
            ),
            padding: EdgeInsets.only(bottom: 20),
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            textDirection: TextDirection.rtl,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(right: 15),
                alignment: Alignment.center,
                width: 30,
                height: 30,
                decoration: BoxDecoration(
                    color: Color(0xFF464EB5),
                    borderRadius: BorderRadius.all(Radius.circular(15))),
                child: Padding(
                  child: Text(
                    item['name'].toString().substring(0, 1),
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 14,
                    ),
                  ),
                  padding: EdgeInsets.only(bottom: 2),
                ),
              ),
              Column(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: <Widget>[
                  Padding(
                    child: Text(
                      item['name'],
                      softWrap: true,
                      style: TextStyle(
                        color: Color(0xFF677092),
                        fontSize: 14,
                      ),
                    ),
                    padding: EdgeInsets.only(right: 20),
                  ),
                  Stack(
                    alignment: Alignment.topRight,
                    children: <Widget>[
                      // Container(
                      //   child: Image(
                      //       width: 11,
                      //       height: 20,
                      //       image: AssetImage(
                      //           "static/images/chat_purple_arrow.png")),
                      //   margin: EdgeInsets.fromLTRB(0, 16, 2, 0),
                      // ),
                      Row(
                        textDirection: TextDirection.rtl,
                        children: <Widget>[
                          ConstrainedBox(
                            child: Container(
                              margin: EdgeInsets.only(top: 8, right: 10),
                              decoration: BoxDecoration(
                                  boxShadow: [
                                    BoxShadow(
                                      offset: Offset(4.0, 7.0),
                                      color: Color(0x04000000),
                                      blurRadius: 10,
                                    ),
                                  ],
                                  color: Colors.blueAccent,
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(10))),
                              padding: EdgeInsets.all(10),
                              child: item['isImage']
                                  ? Image(
                                      height: 100,
                                      image: NetworkImage(
                                        item['reply'] ??
                                            'http://cdn-bj.fis.plus/BC8DDF5A6A594A3185C20FC99666CD49.jpg',
                                      ),
                                    )
                                  : Text(
                                      item['reply'],
                                      softWrap: true,
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 15,
                                      ),
                                    ),
                            ),
                            constraints: BoxConstraints(
                              maxWidth: 800,
                            ),
                          ),
                          Container(
                              margin: EdgeInsets.fromLTRB(0, 8, 8, 0),
                              child: item['status'] == SENDING_TYPE
                                  ? ConstrainedBox(
                                      constraints: BoxConstraints(
                                          maxWidth: 10, maxHeight: 10),
                                      child: Container(
                                        width: 10,
                                        height: 10,
                                        child: CircularProgressIndicator(
                                          strokeWidth: 2.0,
                                          valueColor:
                                              new AlwaysStoppedAnimation<Color>(
                                            Colors.grey,
                                          ),
                                        ),
                                      ),
                                    )
                                  : item['status'] == FAILED_TYPE
                                      ? Image(
                                          width: 11,
                                          height: 20,
                                          image: AssetImage(
                                              "static/images/network_error_icon.png"))
                                      : Container()),
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
          )
        ],
      ),
    );
  }

  final int maxValue = 1 << 32;

  sendTxt() async {
    int tag = random.nextInt(maxValue);
    // if (CommonUtils.isEmpty(textEditingController!.text.trim())) {
    //   return;
    // }
    String message = textEditingController!.text;
    addMessage(message, tag);
    // textEditingController!.text = '';
    // String url = '${Address.getPrefix()}hbpay/overdue/urge/saveReply';
    // var res = await httpManager.netFetch(url,
    //     data: {
    //       'cusUid': userId,
    //       'orderNo': widget.orderNo,
    //       'employeeNo': employeeNo,
    //       'name': userName,
    //       'reply': message,
    //       'tag': '${tag}',
    //     },
    //     options: Options(method: 'post'),
    //     showLoadingForPost: false);

    // int index = 0;
    // if (res.result) {
    //   for (int i = 0; index < list.length; i++) {
    //     if (list[i]['tag'] == res.data) {
    //       index = i;
    //       break;
    //     }
    //   }
    //   setState(() {
    //     list[index]['status'] = SUCCESSED_TYPE;
    //   });
    // } else {
    //   setState(() {
    //     list[index]['status'] = FAILED_TYPE;
    //   });
    // }
  }

  final random = Random();

  addMessage(content, tag) {
    int time = new DateTime.now().millisecondsSinceEpoch;
    setState(() {
      list.insert(0, {
        "createdAt": time,
        "cusUid": userId,
        "employeeNo": employeeNo,
        "name": userName,
        "orderNo": widget.orderNo,
        "reply": content,
        "updatedAt": time,
        'status': SENDING_TYPE,
        'tag': '$tag',
      });
    });
    Timer(Duration(milliseconds: 100), () => _scrollController.jumpTo(0));
  }

  static int SENDING_TYPE = 0;
  static int FAILED_TYPE = 1;
  static int SUCCESSED_TYPE = 2;
}
