Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
5.9 kB
1
Indexable
Never
   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: _refreshMessageController,
              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)),
                                )
                              ],
                            ),
                          ),
                        );
                },
              ),
            ),
          ),
        ),
        
        
        
        ------------------------------------------------------------------
        void _onLoadingMessage() {
    defaultMessageLimit += 20;

    WebServices.socket.emit('get-conversation-between', {
      'User1': customerID, // 1.kişinin ID si
      'User2': Constant.driverInfoModel.sId, //2. kişinin ID si
      'Limit': defaultMessageLimit //Kaç adet mesajın döndürüleceği
    });
  }