Skip to content

Commit

Permalink
Merge pull request #24 from emreesen27/develop-v110
Browse files Browse the repository at this point in the history
1.1.0 done.
  • Loading branch information
emreesen27 authored Jan 21, 2023
2 parents ca45c52 + 7c70db4 commit 926376d
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.1.0] - 20.05.2022
* Bug Fix.
* Cancel option added.
* Dialog status callback added.

## [1.0.9] - 09.12.2022
* Assets path edited.
* The close function can be used with delay.
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.0.9
sn_progress_dialog: ^1.1.0
```
You should then run `flutter packages get`
Expand Down
5 changes: 5 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class Home extends StatelessWidget {
max: 100,
msg: 'File Downloading...',
progressBgColor: Colors.transparent,
cancel: Cancel(
cancelClicked: () {
/// ex: cancel the download
},
),
);
for (int i = 0; i <= 100; i++) {
/// You don't need to update state, just pass the value.
Expand Down
5 changes: 5 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Home extends StatelessWidget {
max: 100,
msg: 'File Downloading...',
progressBgColor: Colors.transparent,
cancel: Cancel(
cancelClicked: () {
/// ex: cancel the download
},
),
);
for (int i = 0; i <= 100; i++) {
/// You don't need to update state, just pass the value.
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.9"
version: "1.1.0"
source_span:
dependency: transitive
description:
Expand Down
Binary file added images/cancel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions lib/options/cancel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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)
final GestureTapCallback? cancelClicked;

/// [cancelImage] The default does not contain any value, if the value is assigned another asset image is created.
final AssetImage? cancelImage;

/// [cancelImageSize] set cancel image dimensions
// (Default: 15.0)
final double cancelImageSize;

/// [cancelImageColor] set cancel image color
// (Default: black)
final Color? cancelImageColor;

Cancel({
this.cancelClicked,
this.cancelImage,
this.cancelImageSize = 15.0,
this.cancelImageColor = Colors.black,
});
}
2 changes: 1 addition & 1 deletion lib/completed.dart → lib/options/completed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class Completed {
/// [completedMsg] Assign the completed Message
// (Default: "completed")
final String completedMsg;
String completedMsg;

/// [completionDelay] The time the dialog window will wait to close
// (Default: 1500 ms)
Expand Down
47 changes: 46 additions & 1 deletion lib/progress_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:sn_progress_dialog/completed.dart';
import 'package:sn_progress_dialog/options/completed.dart';
import 'package:sn_progress_dialog/options/cancel.dart';

enum ValuePosition { center, right }

enum ProgressType { normal, valuable }

enum DialogStatus { opened, closed, completed }

class ProgressDialog {
/// [_progress] Listens to the value of progress.
// Not directly accessible.
Expand All @@ -22,6 +25,10 @@ class ProgressDialog {
// Can only be accessed with the constructor.
late BuildContext _context;

/// [_onStatusChanged] Keeps track of the current status of the dialog window.
// Value assignment is done later.
ValueChanged<DialogStatus>? _onStatusChanged;

ProgressDialog({required context}) {
this._context = context;
}
Expand All @@ -39,6 +46,7 @@ class ProgressDialog {
if (_dialogIsOpen) {
Navigator.pop(_context);
_dialogIsOpen = false;
setDialogStatus(DialogStatus.closed);
}
});
}
Expand All @@ -48,6 +56,11 @@ class ProgressDialog {
return _dialogIsOpen;
}

///[setDialogStatus] Dialog window sets your new state.
void setDialogStatus(DialogStatus status) {
if (_onStatusChanged != null) _onStatusChanged!(status);
}

/// [_valueProgress] Assigns progress properties and updates the value.
// Not directly accessible.
_valueProgress({Color? valueColor, Color? bgColor, required double value}) {
Expand Down Expand Up @@ -87,6 +100,9 @@ class ProgressDialog {
/// [completed] Widgets that will be displayed when the process is completed are assigned through this class.
// If an assignment is not made, the dialog closes without showing anything.

/// [cancel] Use it to have a close button on the dialog.
// Manage other properties related to cancel button via this class.

/// [hideValue] If you are not using the progress value, you can hide it.
// Default (Default: false)

Expand All @@ -98,6 +114,7 @@ class ProgressDialog {
required int max,
required String msg,
Completed? completed,
Cancel? cancel,
ProgressType progressType: ProgressType.normal,
ValuePosition valuePosition: ValuePosition.right,
Color backgroundColor: Colors.white,
Expand All @@ -117,9 +134,12 @@ class ProgressDialog {
bool barrierDismissible: false,
bool hideValue: false,
int closeWithDelay: 100,
ValueChanged<DialogStatus>? onStatusChanged,
}) {
_dialogIsOpen = true;
_msg.value = msg;
_onStatusChanged = onStatusChanged;
setDialogStatus(DialogStatus.opened);
return showDialog(
barrierDismissible: barrierDismissible,
barrierColor: barrierColor,
Expand All @@ -137,13 +157,38 @@ class ProgressDialog {
valueListenable: _progress,
builder: (BuildContext context, dynamic value, Widget? child) {
if (value == max) {
setDialogStatus(DialogStatus.completed);
completed == null
? close(delay: closeWithDelay)
: close(delay: completed.completionDelay);
}
return Column(
mainAxisSize: MainAxisSize.min,
children: [
cancel != null
? Align(
alignment: Alignment.topRight,
child: InkWell(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
onTap: () {
close();
if (cancel.cancelClicked != null)
cancel.cancelClicked!();
},
child: Image(
width: cancel.cancelImageSize,
height: cancel.cancelImageSize,
color: cancel.cancelImageColor,
image: cancel.cancelImage ??
AssetImage(
"images/cancel.png",
package: "sn_progress_dialog",
),
),
),
)
: Container(),
Row(
children: [
value == max && completed != null
Expand Down
3 changes: 2 additions & 1 deletion lib/sn_progress_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ library sn_progress_dialog;

/// Exporting package files
export 'progress_dialog.dart';
export 'completed.dart';
export 'options/completed.dart';
export 'options/cancel.dart';
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: sn_progress_dialog
description: Customizable progress dialog package for Flutter.(Captures the progress value)
version: 1.0.9
author: A.Emre ESEN <emreesen27@gmail.com>
version: 1.1.0
homepage: https://github.com/emreesen27/Flutter-Progress-Dialog.git

environment:
Expand All @@ -25,6 +24,7 @@ flutter:
# To add assets to your package, add an assets section, like this:
assets:
- images/completed.png
- images/cancel.png
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
Expand Down

0 comments on commit 926376d

Please sign in to comment.