Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
11 kB
0
Indexable
Never
  Widget messageDialogWidget() {
    double width = Constant.width * 0.35;
    double height = Constant.height * 0.8;
    return Stack(
      children: [
        Align(
          alignment: Alignment.center,
          child: Container(
            width: Constant.width * 0.1,
            height: Constant.width * 0.1,
            decoration: const BoxDecoration(
                image: DecorationImage(
                    opacity: 0.75,
                    fit: BoxFit.fitWidth,
                    image: AssetImage("assets/images/logopars.png")),
                borderRadius: BorderRadius.all(Radius.circular(20))),
          ),
        ),
        Positioned(
          top: 0,
          bottom: height * 0.15,
          width: width,
          child: RefreshConfiguration(
            child: SmartRefresher(
              enablePullDown: false,
              enablePullUp: true,
              footer: CustomFooter(
                builder: (BuildContext context, LoadStatus mode) {
                  Widget body;
                  if (mode == LoadStatus.idle) {
                    body =
                        Text("Daha fazla yüklemek için yukarı doğru kaydırın",
                            style: TextStyle(
                              color: Colors.amber,
                            ));
                  } else if (mode == LoadStatus.loading) {
                    body = CircularProgressIndicator();
                  } else if (mode == LoadStatus.failed) {
                    body = Text("Yüklenirken hata oluştu",
                        style: TextStyle(
                          color: Colors.amber,
                        ));
                  } else if (mode == LoadStatus.canLoading) {
                    body = Text("Daha fazla yüklemek için serbest bırakın.",
                        style: TextStyle(
                          color: Colors.amber,
                        ));
                  } else {
                    body = Text("Yüklenecek veri bulunamadı.",
                        style: TextStyle(
                          color: Colors.amber,
                        ));
                  }
                  return Container(
                    height: 55.0,
                    child: Center(child: body),
                  );
                },
              ),
              controller: _refreshController,
              onLoading: _onLoadingMessage,
              child: ListView.builder(
                key: UniqueKey(),
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                reverse: true,
                cacheExtent: 1000,
                itemCount: MessageModel.messages.length,
                itemBuilder: (BuildContext context, int index) {
                  var message = MessageModel.messages[index];
                  return (message.sender == Constant.driverInfoModel.sId)
                      ? ChatBubble(
                          clipper:
                              ChatBubbleClipper4(type: BubbleType.sendBubble),
                          alignment: Alignment.topRight,
                          margin: EdgeInsets.only(top: 5, bottom: 5),
                          backGroundColor: Colors.yellow[100],
                          child: Container(
                            constraints: BoxConstraints(maxWidth: width * 0.7),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                    DateFormat('dd/MM/yyy - kk:mm').format(
                                        DateTime.fromMillisecondsSinceEpoch(
                                            message.timeStamp
                                                .toLocal()
                                                .millisecondsSinceEpoch)),
                                    style: TextStyle(
                                        color: Colors.grey, fontSize: 15)),
                                Padding(
                                  padding:
                                      const EdgeInsets.only(top: 5, bottom: 5),
                                  child: Text(message.message,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 20)),
                                )
                              ],
                            ),
                          ),
                        )
                      : ChatBubble(
                          clipper: ChatBubbleClipper4(
                              type: BubbleType.receiverBubble),
                          alignment: Alignment.topLeft,
                          margin: EdgeInsets.only(top: 3, bottom: 3),
                          backGroundColor: Colors.grey[100],
                          child: Container(
                            constraints: BoxConstraints(maxWidth: width * 0.7),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                    '$customerName @${DateFormat('dd/MM/yyy - kk:mm').format(DateTime.fromMillisecondsSinceEpoch(message.timeStamp.toLocal().millisecondsSinceEpoch))}',
                                    style: TextStyle(
                                        color: Colors.grey, fontSize: 15)),
                                Padding(
                                  padding:
                                      const EdgeInsets.only(top: 3, bottom: 3),
                                  child: Text(message.message,
                                      style: TextStyle(
                                          color: Colors.black, fontSize: 20)),
                                )
                              ],
                            ),
                          ),
                        );
                },
              ),
            ),
          ),
        ),
        Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              height: height * 0.15,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  bottomLeft: Radius.circular(40),
                  bottomRight: Radius.circular(40),
                ),
              ),
              padding: EdgeInsets.only(
                  bottom: height * 0.02,
                  left: width * 0.05,
                  top: height * 0.02,
                  right: width * 0.01),
              child: Row(
                children: [
                  Expanded(
                    flex: 8,
                    child: FocusScope(
                      child: Focus(
                        onFocusChange: (value) {
                          setState(() {
                            (isFocusOn) ? isFocusOn = false : isFocusOn = true;
                          });
                        },
                        child: customerID == Constant.currentCustomerID
                            ? Padding(
                                padding: EdgeInsets.only(left: width * 0.045),
                                child: TextFormField(
                                  enabled: onDuty &&
                                      Constant.currentCustomerID == customerID,
                                  controller: messageController,
                                  decoration: InputDecoration(
                                    border: OutlineInputBorder(
                                        borderRadius:
                                            BorderRadius.circular(40)),
                                  ),
                                  onChanged: (value) {
                                    if (value == "") {
                                      setState(() {});
                                    } else if (value.length == 1) {
                                      setState(() {});
                                    }
                                  },
                                ),
                              )
                            : Padding(
                                padding: EdgeInsets.only(left: width * 0.045),
                                child: Container(
                                  height: Constant.height,
                                  decoration: BoxDecoration(
                                    color: Colors.grey[300],
                                    border: Border.all(
                                        width: 1, color: Colors.grey[400]),
                                    borderRadius: BorderRadius.circular(30),
                                  ),
                                  child: Center(
                                    child: Padding(
                                      padding: EdgeInsets.only(
                                          left: width * 0.040,
                                          right: width * 0.025),
                                      child: AutoSizeText(
                                        "Sadece aktif seyahatinizdeki müşteriyle iletişime geçebilirsiniz",
                                        maxLines: 2,
                                        style: TextStyle(
                                          fontSize: 100,
                                          fontStyle: FontStyle.italic,
                                          color: Colors.grey[700],
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                      ),
                    ),
                  ),
                  Expanded(
                    flex: 2,
                    child: FittedBox(
                      fit: BoxFit.cover,
                      child: IconButton(
                        color: Colors.blue[900],
                        icon: Icon(Icons.send),
                        onPressed: (messageController.text.isNotEmpty) &&
                                onDuty &&
                                Constant.currentCustomerID == customerID
                            ? () {
                                print(messageController.text);
                                _sendMessage();
                              }
                            : null,
                      ),
                    ),
                  )
                ],
              ),
            )),
      ],
    );
  }