fileWidget function

Widget fileWidget(
  1. PersonChat data,
  2. dynamic state,
  3. dynamic context,
  4. dynamic onDownloadPressed,
)

Implementation

Widget fileWidget(PersonChat data, state, context, onDownloadPressed) {
  if (data.type == Person.other && data.chatType.status == 0) {
    return GestureDetector(
      onTap: () {
        onDownloadPressed();
      },
      child: Stack(
        alignment: Alignment.center,
        children: [
          const Icon(Icons.file_download),
          CircularProgressIndicator(
            strokeWidth: 2,
            value: (data.chatType.progress / 100),
          ),
        ],
      ),
    );
  }
  if (data.chatType.file == Files.image && (data.chatType.path != '' && data.chatType.path != null)) {
    return GestureDetector(
      onTap: () {
        onDownloadPressed();
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => ImageViewer(
              path: data.chatType.path ?? '',
            ),
          ),
        );
      },
      child: Stack(
        alignment: Alignment.center,
        children: [
          Container(
            width: 150,
            height: 150,
            decoration: BoxDecoration(
              borderRadius: data.type == Person.me
                  ? const BorderRadius.only(
                      topLeft: Radius.circular(16),
                      topRight: Radius.circular(16),
                      bottomLeft: Radius.circular(16),
                    )
                  : const BorderRadius.only(
                      topLeft: Radius.circular(16),
                      topRight: Radius.circular(16),
                      bottomRight: Radius.circular(16),
                    ),
              image: DecorationImage(
                image: FileImage(
                  File(data.chatType.path!),
                ),
                fit: BoxFit.cover,
              ),
            ),
          ),
          data.chatType.progress == 100
              ? const SizedBox()
              : SizedBox(
                  width: 50,
                  height: 50,
                  child: CircularProgressIndicator(
                    strokeWidth: 2,
                    value: data.chatType.progress == 100 || data.chatType.progress == 0 ? null : (data.chatType.progress / 100),
                  ),
                ),
        ],
      ),
    );
  } else if (data.chatType.file == Files.video && data.chatType.status == 1) {
    return GestureDetector(
      onTap: () {
        onDownloadPressed();
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => HunterPlayer(
              path: data.chatType.path ?? '',
            ),
          ),
        );
      },
      child: Stack(
        alignment: Alignment.center,
        children: [
          ClipRRect(
            child: Image.memory(data.chatType.thumnailMemory!),
            borderRadius: data.type == Person.me
                ? const BorderRadius.only(
                    topLeft: Radius.circular(16),
                    topRight: Radius.circular(16),
                    bottomLeft: Radius.circular(16),
                  )
                : const BorderRadius.only(
                    topLeft: Radius.circular(16),
                    topRight: Radius.circular(16),
                    bottomRight: Radius.circular(16),
                  ),
          ),
          const Icon(
            Icons.play_arrow,
            size: 40,
          ),
          data.chatType.progress == 100
              ? const SizedBox()
              : SizedBox(
                  width: 50,
                  height: 50,
                  child: CircularProgressIndicator(
                    strokeWidth: 2,
                    value: data.chatType.progress == 100 || data.chatType.progress == 0 ? null : (data.chatType.progress / 100),
                  ),
                ),
        ],
      ),
    );
  }
  return const SizedBox();
}