Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.2.0 is completed #41

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.2.0]- 10.12.2024
* `completedMsgFuture` support for asynchronous completion messages
* `dispose()` method to properly release resources
* Deprecated old ProgressType values: normal and valuable


## [1.1.4] - 09.03.2024

* Added support for `useRootNavigator` parameter in the `ProgressDialog` constructor.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Progress dialog package for flutter
You must add the library as a dependency to your project.
```yaml
dependencies:
sn_progress_dialog: ^1.1.4
sn_progress_dialog: ^1.2.0
```

You should then run `flutter packages get`
Expand Down
32 changes: 14 additions & 18 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ class Home extends StatelessWidget {
);
for (int i = 0; i <= 100; i++) {
/// You don't need to update state, just pass the value.
/// Only value required
pd.update(value: i);
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}

/// Shows a progress dialog with a determinate progress bar.
_valuableProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);

pd.show(
max: 100,
msg: 'File Downloading...',

/// Assign the type of progress bar.
progressType: ProgressType.valuable,
);
for (int i = 0; i <= 100; i++) {
Expand All @@ -57,50 +55,46 @@ class Home extends StatelessWidget {
}
}

/// Shows a progress dialog that starts with a preparation message,
/// then switches to a downloading message.
_preparingProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);

/// show the state of preparation first.
pd.show(
max: 100,
msg: 'Preparing Download...',
progressType: ProgressType.valuable,
progressType: ProgressType.determinate,
);

/// Added to test late loading starts
await Future.delayed(Duration(milliseconds: 3000));
for (int i = 0; i <= 100; i++) {
/// You can indicate here that the download has started.
pd.update(value: i, msg: 'File Downloading...');
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}

/// Shows a customizable progress dialog with a dark theme.
_customProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);

/// show the state of preparation first.
pd.show(
max: 100,
msg: 'Preparing Download...',
progressType: ProgressType.valuable,
progressType: ProgressType.determinate,
backgroundColor: Color(0xff212121),
progressValueColor: Color(0xff3550B4),
progressBgColor: Colors.white70,
msgColor: Colors.white,
valueColor: Colors.white);

/// Added to test late loading starts
await Future.delayed(Duration(milliseconds: 3000));
for (int i = 0; i <= 100; i++) {
/// You can indicate here that the download has started.
pd.update(value: i, msg: 'File Downloading...');
i++;
await Future.delayed(Duration(milliseconds: 100));
}
}

/// Shows a progress dialog that completes with a custom completion widget.
_completedProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
Expand All @@ -118,6 +112,7 @@ class Home extends StatelessWidget {
}
}

/// Shows a message-only progress dialog without a progress bar.
_onlyMessageProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
Expand All @@ -126,31 +121,32 @@ class Home extends StatelessWidget {
hideValue: true,
);

/** You can update the message value after a certain action **/
await Future.delayed(Duration(milliseconds: 1000));
pd.update(msg: "Almost done...");

await Future.delayed(Duration(milliseconds: 1000));
pd.close();
}

/// Shows a message-only progress dialog that completes automatically.
_onlyMessageWithCompletionProgress(context) async {
ProgressDialog pd = ProgressDialog(context: context);
pd.show(
barrierDismissible: true,
msg: "Please waiting...",
hideValue: true,
completed: Completed(), // Set Completed
completed: Completed(completionDelay: 1500), // Set Completed
);

/** You can update the message value after a certain action **/
await Future.delayed(Duration(milliseconds: 1000));

pd.update(msg: "Almost done...");

await Future.delayed(Duration(milliseconds: 1000));
/**
* if you can't assign value and want to use completed object. You should set the Value to 100.
* The dialog will close automatically.
* **/
pd.update(msg: "Almost done...", value: 100);
pd.update(value: 100);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.4"
version: "1.2.0"
source_span:
dependency: transitive
description:
Expand Down
11 changes: 11 additions & 0 deletions lib/enums/dialog_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Represents the current status of the dialog.
enum DialogStatus {
/// Dialog is currently displayed
opened,

/// Dialog has been closed
closed,

/// Dialog has completed its progress
completed
}
25 changes: 25 additions & 0 deletions lib/enums/progress_types.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enum ProgressType {
/// Indeterminate progress indicator
@Deprecated(
'Use indeterminate instead. This will be removed in the next major version.')
normal,

/// Progress indicator with value
@Deprecated(
'Use determinate instead. This will be removed in the next major version.')
valuable,

/// Shows an infinite spinning progress indicator without specific progress value
indeterminate,

/// Shows progress with specific value (0-100%)
determinate,
}

extension ProgressTypeHelper on ProgressType {
bool get isIndeterminate =>
this == ProgressType.normal || this == ProgressType.indeterminate;

bool get isDeterminate =>
this == ProgressType.valuable || this == ProgressType.determinate;
}
8 changes: 8 additions & 0 deletions lib/enums/value_position.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Determines the position of the progress value text.
enum ValuePosition {
/// Center aligned progress value
center,

/// Right aligned progress value
right
}
19 changes: 10 additions & 9 deletions lib/options/cancel.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import 'package:flutter/material.dart';

class Cancel {
/// [cancelClicked] If you want to execute an action when the dialog is canceled, pass a void function.
// (Default: null)
/// Callback function that will be executed when cancel button is tapped.
final GestureTapCallback? cancelClicked;

/// [cancelImage] The default does not contain any value, if the value is assigned another asset image is created.
/// Custom image to use for the cancel button.
/// If not provided, uses default cancel icon.
final AssetImage? cancelImage;

/// [cancelImageSize] set cancel image dimensions
// (Default: 15.0)
/// Size of the cancel button image in pixels.
/// Defaults to 15.0.
final double cancelImageSize;

/// [cancelImageColor] set cancel image color
// (Default: black)
/// Color to apply to the cancel button image.
/// Defaults to Colors.black.
final Color? cancelImageColor;

/// [autoHidden] It hides the cancel button when value and max are equal.
// (Default: true)
/// Whether to automatically hide the cancel button when progress completes.
/// When true, the button will be hidden when progress value equals max value.
/// Defaults to true.
final bool autoHidden;

Cancel({
Expand Down
18 changes: 12 additions & 6 deletions lib/options/completed.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import 'package:flutter/material.dart';

class Completed {
/// [completedMsg] Assign the completed Message
// (Default: "completed")
String completedMsg;
/// Future that resolves to the completion message.
/// If provided, this message will override [completedMsg] when resolved.
final Future<String>? completedMsgFuture;

/// [completionDelay] The time the dialog window will wait to close
// (Default: 1500 ms)
/// Message to display when progress completes.
/// Defaults to "Completed !".
final String completedMsg;

/// Duration to wait before closing the dialog after completion, in milliseconds.
/// Defaults to 1500ms.
final int completionDelay;

/// [completedImage] The default does not contain any value, if the value is assigned another asset image is created.
/// Custom image to display when progress completes.
/// If not provided, uses default completion icon.
final AssetImage? completedImage;

Completed({
this.completedMsgFuture,
this.completedMsg = "Completed !",
this.completionDelay = 1500,
this.completedImage,
Expand Down
Loading
Loading