Skip to content

Commit

Permalink
feat: created DSProgressiveProgress widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Rossi committed Nov 13, 2023
1 parent 6ed4641 commit 3073413
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 52 deletions.
2 changes: 2 additions & 0 deletions lib/blip_ds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,6 @@ export 'src/widgets/utils/ds_file_extension_icon.util.dart'
export 'src/widgets/utils/ds_group_card.widget.dart' show DSGroupCard;
export 'src/widgets/utils/ds_header.widget.dart' show DSHeader;
export 'src/widgets/utils/ds_progress_bar.widget.dart' show DSProgressBar;
export 'src/widgets/utils/ds_progressive_progress.widget.dart'
show DSProgressiveProgress;
export 'src/widgets/utils/ds_user_avatar.widget.dart' show DSUserAvatar;
28 changes: 6 additions & 22 deletions lib/src/widgets/chat/ds_image_message_bubble.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../../models/ds_message_bubble_style.model.dart';
import '../../themes/colors/ds_colors.theme.dart';
import '../texts/ds_caption_text.widget.dart';
import '../utils/ds_expanded_image.widget.dart';
import '../utils/ds_progressive_progress.widget.dart';
import 'ds_document_select.widget.dart';
import 'ds_message_bubble.widget.dart';
import 'ds_show_more_text.widget.dart';
Expand Down Expand Up @@ -114,7 +115,11 @@ class _DSImageMessageBubbleState extends State<DSImageMessageBubble>
isLoading: false,
shouldAuthenticate: widget.shouldAuthenticate,
)
: _buildDownloadProgress(),
: DSProgressiveProgress(
currentProgress: _controller.downloadProgress,
maximumProgress: _controller.maximumProgress,
foregroundColor: foregroundColor,
),
),
if ((widget.title?.isNotEmpty ?? false) ||
(widget.text?.isNotEmpty ?? false))
Expand Down Expand Up @@ -161,27 +166,6 @@ class _DSImageMessageBubbleState extends State<DSImageMessageBubble>
);
}

Widget _buildDownloadProgress() {
final foregroundColor = widget.style.isLightBubbleBackground(widget.align)
? DSColors.neutralDarkCity
: DSColors.neutralLightSnow;

final double percent = _controller.maximumProgress.value > 0
? _controller.downloadProgress.value / _controller.maximumProgress.value
: 0;

return Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: CircularProgressIndicator(
color: foregroundColor,
backgroundColor: Colors.grey,
value: percent,
),
),
);
}

@override
bool get wantKeepAlive => true;
}
36 changes: 6 additions & 30 deletions lib/src/widgets/chat/video/ds_video_message_bubble.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../../../services/ds_auth.service.dart';
import '../../../themes/colors/ds_colors.theme.dart';
import '../../../themes/icons/ds_icons.dart';
import '../../buttons/ds_button.widget.dart';
import '../../texts/ds_caption_small_text.widget.dart';
import '../../utils/ds_progressive_progress.widget.dart';
import '../ds_message_bubble.widget.dart';
import '../ds_show_more_text.widget.dart';
import 'ds_video_body.widget.dart';
Expand Down Expand Up @@ -131,7 +131,11 @@ class _DSVideoMessageBubbleState extends State<DSVideoMessageBubble>
color: DSColors.neutralDarkRooftop,
)
: _controller.isDownloading.value
? _buildDownloadProgress(foregroundColor)
? DSProgressiveProgress(
currentProgress: _controller.downloadProgress,
maximumProgress: _controller.maximumProgress,
foregroundColor: foregroundColor,
)
: _controller.thumbnail.isEmpty
? Center(
child: SizedBox(
Expand Down Expand Up @@ -186,32 +190,4 @@ class _DSVideoMessageBubbleState extends State<DSVideoMessageBubble>
),
);
}

Widget _buildDownloadProgress(final Color foregroundColor) {
final double percent = _controller.maximumProgress.value > 0
? _controller.downloadProgress.value / _controller.maximumProgress.value
: 0;

return AnimatedOpacity(
opacity: _controller.maximumProgress.value > 0 ? 1 : 0,
duration: const Duration(milliseconds: 250),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: CircularProgressIndicator(
color: foregroundColor,
backgroundColor: Colors.grey,
value: percent,
),
),
DSCaptionSmallText(
_controller.getDownloadProgress(),
color: foregroundColor,
)
],
),
);
}
}
64 changes: 64 additions & 0 deletions lib/src/widgets/utils/ds_progressive_progress.widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:file_sizes/file_sizes.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../themes/colors/ds_colors.theme.dart';
import '../texts/ds_caption_small_text.widget.dart';

class DSProgressiveProgress extends StatelessWidget {
final RxInt maximumProgress;
final RxInt currentProgress;
final Color? foregroundColor;

const DSProgressiveProgress({
super.key,
required this.maximumProgress,
required this.currentProgress,
this.foregroundColor,
});

@override
Widget build(BuildContext context) {
return Obx(
() {
final double percent = maximumProgress.value > 0
? currentProgress.value / maximumProgress.value
: 0;

return SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: CircularProgressIndicator(
color: DSColors.primary,
backgroundColor: Colors.grey,
value: currentProgress.value < maximumProgress.value
? percent
: null,
),
),
DSCaptionSmallText(
_buildProgress(),
color: foregroundColor ?? DSColors.neutralDarkCity,
)
],
),
);
},
);
}

String _buildProgress() {
String getSize(int value) => FileSize.getSize(
value,
precision: PrecisionValue.One,
);

return '${getSize(currentProgress.value)} / ${getSize(maximumProgress.value)}';
}
}

0 comments on commit 3073413

Please sign in to comment.