mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can cancel file sending
This commit is contained in:
		@@ -24,6 +24,7 @@ import 'package:comunic/utils/list_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/log_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/video_utils.dart';
 | 
			
		||||
import 'package:dio/dio.dart';
 | 
			
		||||
import 'package:emoji_picker/emoji_picker.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:mime/mime.dart';
 | 
			
		||||
@@ -65,6 +66,9 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
 | 
			
		||||
  ScrollWatcher _scrollController;
 | 
			
		||||
  _OlderMessagesLevel _loadingOlderMessages = _OlderMessagesLevel.NONE;
 | 
			
		||||
 | 
			
		||||
  CancelToken _sendCancel;
 | 
			
		||||
  double _sendProgress;
 | 
			
		||||
 | 
			
		||||
  String get textMessage => _textController.text;
 | 
			
		||||
 | 
			
		||||
  bool get _isMessageValid =>
 | 
			
		||||
@@ -292,17 +296,28 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
 | 
			
		||||
          maxWidth: srvConfig.conversationsPolicy.maxThumbnailWidth,
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
      await _submitMessage(
 | 
			
		||||
      _sendCancel = CancelToken();
 | 
			
		||||
      final progressCb =
 | 
			
		||||
          (count, total) => setState(() => _sendProgress = count / total);
 | 
			
		||||
      final res = await ConversationsHelper().sendMessage(
 | 
			
		||||
        NewConversationMessage(
 | 
			
		||||
            conversationID: widget.conversationID,
 | 
			
		||||
            message: null,
 | 
			
		||||
            file: file,
 | 
			
		||||
            thumbnail: thumbnail),
 | 
			
		||||
        sendProgress: progressCb,
 | 
			
		||||
        cancelToken: _sendCancel,
 | 
			
		||||
      );
 | 
			
		||||
      assert(res == SendMessageResult.SUCCESS);
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      logError(e, s);
 | 
			
		||||
      showSimpleSnack(context, tr("Failed to send a file!"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _sendCancel = null;
 | 
			
		||||
      _sendProgress = null;
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Send a new text message
 | 
			
		||||
@@ -590,6 +605,28 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
 | 
			
		||||
        numRecommended: 50,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildSendingWidget() => Container(
 | 
			
		||||
        height: 68,
 | 
			
		||||
        color: _senderColor,
 | 
			
		||||
        child: Row(
 | 
			
		||||
          children: <Widget>[
 | 
			
		||||
            Spacer(flex: 1),
 | 
			
		||||
            Flexible(
 | 
			
		||||
              child: LinearProgressIndicator(value: _sendProgress),
 | 
			
		||||
              flex: 5,
 | 
			
		||||
            ),
 | 
			
		||||
            Spacer(flex: 1),
 | 
			
		||||
            Text("${(_sendProgress * 100).toInt()}%"),
 | 
			
		||||
            Spacer(flex: 1),
 | 
			
		||||
            OutlineButton(
 | 
			
		||||
              onPressed: () => _sendCancel.cancel(),
 | 
			
		||||
              child: Text(tr("Cancel").toUpperCase()),
 | 
			
		||||
            ),
 | 
			
		||||
            Spacer(flex: 1),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    if (_error == ErrorLevel.MAJOR) return _buildError();
 | 
			
		||||
@@ -607,7 +644,7 @@ class _ConversationScreenState extends SafeState<ConversationScreen> {
 | 
			
		||||
              : null,
 | 
			
		||||
        ),
 | 
			
		||||
        _messages.length == 0 ? _buildNoMessagesNotice() : _buildMessagesList(),
 | 
			
		||||
        _buildSendMessageForm(),
 | 
			
		||||
        _sendCancel != null ? _buildSendingWidget() : _buildSendMessageForm(),
 | 
			
		||||
        _showEmojiPicker ? _buildEmojiContainer() : Container(),
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user