diff --git a/lib/src/core/toastification.dart b/lib/src/core/toastification.dart index ac64cebf..40c4cd7e 100644 --- a/lib/src/core/toastification.dart +++ b/lib/src/core/toastification.dart @@ -6,6 +6,8 @@ import 'package:toastification/src/core/toastification_manager.dart'; import 'package:toastification/src/widget/built_in/built_in.dart'; import 'package:toastification/src/widget/built_in/built_in_builder.dart'; +// TODO(payam): add navigator observer + /// This is the main singleton class instance of the package. /// You can use this instance to show and manage your notifications. /// @@ -19,7 +21,7 @@ import 'package:toastification/src/widget/built_in/built_in_builder.dart'; /// title: 'Hello World', /// description: 'This is a notification', /// type: ToastificationType.info, -/// style: ToastificationStyle.floating, +/// style: ToastificationStyle.flat, /// autoCloseDuration: Duration(seconds: 3), /// ); /// ``` @@ -54,7 +56,7 @@ final toastification = Toastification(); /// title: 'Hello World', /// description: 'This is a notification', /// type: ToastificationType.info, -/// style: ToastificationStyle.floating, +/// style: ToastificationStyle.flat, /// autoCloseDuration: Duration(seconds: 3), /// ); /// ``` @@ -84,8 +86,14 @@ class Toastification { final Map _managers = {}; /// shows a custom notification + /// /// you should create your own widget and pass it to the [builder] parameter + /// in the [builder] parameter you have the access to [ToastificationItem] + /// so you may want to use that to create your widget. /// + /// the return value is a [ToastificationItem] that you can use to dismiss the notification + /// or find the notification details by its [id] + /// /// example : /// /// ```dart @@ -138,6 +146,10 @@ class Toastification { /// using this method you can show a notification by using the [navigator] overlay /// you should create your own widget and pass it to the [builder] parameter /// + /// + /// the return value is a [ToastificationItem] that you can use to dismiss the notification + /// or find the notification details by its [id] + /// /// ```dart /// toastification.showWithNavigatorState( /// navigator: navigatorState or Navigator.of(context), @@ -172,7 +184,12 @@ class Toastification { ); } - /// shows a built-in notification with the given parameters + /// shows a predefined toast widget base on the parameters + /// + /// you can use this method to show a built-in toasts + /// + /// the return value is a [ToastificationItem] that you can use to dismiss the notification + /// or find the notification details by its [id] /// /// example : /// @@ -183,11 +200,10 @@ class Toastification { /// title: 'Hello World', /// description: 'This is a notification', /// type: ToastificationType.info, - /// style: ToastificationStyle.floating, + /// style: ToastificationStyle.flat, /// autoCloseDuration: Duration(seconds: 3), /// ); /// ``` - // TODO(payam): add brightness and dark mode items ToastificationItem show({ required BuildContext context, AlignmentGeometry? alignment, diff --git a/lib/src/core/toastification_config.dart b/lib/src/core/toastification_config.dart index 7515c984..e7bd4d31 100644 --- a/lib/src/core/toastification_config.dart +++ b/lib/src/core/toastification_config.dart @@ -13,7 +13,11 @@ const _defaultMargin = EdgeInsets.symmetric(vertical: 32); /// if some of the parameters are not provided, /// /// [Toastification] will use this class to get the default values. -/// +/// +/// to provide the [ToastificationConfig] to the widget tree you can use +/// the [ToastificationConfigProvider] widget. +/// +/// class ToastificationConfig extends Equatable { const ToastificationConfig({ this.alignment = _defaultAlignment, diff --git a/lib/src/core/toastification_item.dart b/lib/src/core/toastification_item.dart index 8758d77b..e0574749 100644 --- a/lib/src/core/toastification_item.dart +++ b/lib/src/core/toastification_item.dart @@ -4,7 +4,7 @@ import 'package:pausable_timer/pausable_timer.dart'; import 'package:uuid/uuid.dart'; const _uuid = Uuid(); - + /// enum to define the status of the timer of the toastification item /// [init] : the timer is not started yet /// [started] : the timer is started @@ -13,10 +13,20 @@ const _uuid = Uuid(); /// [finished] : the timer is finished /// enum ToastTimeStatus { + + /// the timer is not started yet init, + + /// the timer is started started, + + /// the timer is paused paused, + + /// the timer is stopped stopped, + + /// the timer is completed finished, } @@ -93,8 +103,10 @@ class ToastificationItem implements Equatable { /// the animation duration of the toastification item animation final Duration? animationDuration; + /// the timer of the toastification item late final PausableTimer? _timer; + /// the status notifier of the timer final ValueNotifier _timeStatus = ValueNotifier(ToastTimeStatus.init); diff --git a/lib/src/core/toastification_manager.dart b/lib/src/core/toastification_manager.dart index 0eae8953..d5eea136 100644 --- a/lib/src/core/toastification_manager.dart +++ b/lib/src/core/toastification_manager.dart @@ -23,10 +23,6 @@ class ToastificationManager { /// if the list is empty, the overlay entry will be removed final List _notifications = []; - /// using this method you can show a notification - /// if there is no notification in the notification list, - /// we will animate in the overlay - /// otherwise we will just add the notification to the list ToastificationItem showCustom({ required BuildContext context, required ToastificationBuilder builder, @@ -82,7 +78,7 @@ class ToastificationManager { } } - /// using this method you can remove a notification + /// using this method you can remove a notification item /// if there is no notification in the notification list, /// we will remove the overlay entry /// @@ -147,8 +143,8 @@ class ToastificationManager { } /// This function dismisses all the notifications in the [_notifications] list. - /// The delayForAnimation parameter is optional and defaults to true. - /// When true, it adds a delay for better animation. + /// The [delayForAnimation] parameter is optional and defaults to true. + /// When it is true, it adds a delay for better animation. void dismissAll({bool delayForAnimation = true}) async { // Creates a new list cloneList that has all the notifications from the _notifications list, but in reverse order. final cloneList = _notifications.toList(growable: false).reversed; diff --git a/lib/src/widget/built_in/built_in.dart b/lib/src/widget/built_in/built_in.dart index 6370978a..78128349 100644 --- a/lib/src/widget/built_in/built_in.dart +++ b/lib/src/widget/built_in/built_in.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:toastification/src/widget/built_in/built_in_style.dart'; +/// enum to define the style of the built-in toastification enum ToastificationStyle { minimal, fillColored, @@ -8,19 +9,33 @@ enum ToastificationStyle { flat, } +/// enum to define the type of the built-in toastification enum ToastificationType { + /// info toast to show some information - blue color - icon: info info, + + /// warning toast to show some warning - yellow color - icon: warning warning, + + /// error toast to show some error - red color - icon: error success, + + /// success toast to show some success - green color - icon: success error, } +/// Using this enum you can define the behavior of the toast close button enum CloseButtonShowType { - always('Always'), - onHover('On Hover'), - none('None'); + /// [always] - show the close button always + always._('Always'), + + /// [onHover] - show the close button only when the mouse is hovering the toast + onHover._('On Hover'), + + /// [none] - do not show the close button + none._('None'); - const CloseButtonShowType(this.title); + const CloseButtonShowType._(this.title); final String title; @@ -30,6 +45,9 @@ enum CloseButtonShowType { String toValueString() => '$CloseButtonShowType.$name'; } +/// Creates the built-in toastification content - title, description, progress bar +/// +/// This widget is used by the built-in toastification widgets class BuiltInContent extends StatelessWidget { const BuiltInContent({ super.key, diff --git a/lib/src/widget/built_in/built_in_builder.dart b/lib/src/widget/built_in/built_in_builder.dart index 0fd67573..69a8e3d3 100644 --- a/lib/src/widget/built_in/built_in_builder.dart +++ b/lib/src/widget/built_in/built_in_builder.dart @@ -2,6 +2,7 @@ import 'dart:ui'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; +import 'package:toastification/src/helper/toast_helper.dart'; import 'package:toastification/src/widget/built_in/widget/on_hover_builder.dart'; import 'package:toastification/toastification.dart'; diff --git a/lib/src/widget/built_in/built_in_style.dart b/lib/src/widget/built_in/built_in_style.dart index f7670545..98b7edb9 100644 --- a/lib/src/widget/built_in/built_in_style.dart +++ b/lib/src/widget/built_in/built_in_style.dart @@ -15,6 +15,7 @@ const lowModeShadow = [ spreadRadius: 0, ) ]; + const highModeShadow = [ BoxShadow( color: Color(0x14000000), diff --git a/lib/src/widget/built_in/filled/filled_style.dart b/lib/src/widget/built_in/filled/filled_style.dart index 9f7824fe..d30b5481 100644 --- a/lib/src/widget/built_in/filled/filled_style.dart +++ b/lib/src/widget/built_in/filled/filled_style.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:toastification/src/helper/toast_helper.dart'; import 'package:toastification/toastification.dart'; class FilledStyle extends BuiltInStyle { diff --git a/lib/src/widget/built_in/flat/flat_style.dart b/lib/src/widget/built_in/flat/flat_style.dart index 8c2b33c7..aab809e4 100644 --- a/lib/src/widget/built_in/flat/flat_style.dart +++ b/lib/src/widget/built_in/flat/flat_style.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:toastification/src/helper/toast_helper.dart'; import 'package:toastification/toastification.dart'; class FlatStyle extends BuiltInStyle { diff --git a/lib/src/widget/built_in/flat_colored/flat_colored_style.dart b/lib/src/widget/built_in/flat_colored/flat_colored_style.dart index 4f1d4f77..c894f536 100644 --- a/lib/src/widget/built_in/flat_colored/flat_colored_style.dart +++ b/lib/src/widget/built_in/flat_colored/flat_colored_style.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:toastification/src/helper/toast_helper.dart'; import 'package:toastification/toastification.dart'; class FlatColoredStyle extends BuiltInStyle { diff --git a/lib/src/widget/built_in/minimal/minimal_style.dart b/lib/src/widget/built_in/minimal/minimal_style.dart index 9c2d9a4b..df912c61 100644 --- a/lib/src/widget/built_in/minimal/minimal_style.dart +++ b/lib/src/widget/built_in/minimal/minimal_style.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:toastification/src/helper/toast_helper.dart'; import 'package:toastification/toastification.dart'; class MinimalStyle extends BuiltInStyle { diff --git a/lib/src/widget/toast_animation.dart b/lib/src/widget/toast_animation.dart index 7b772fb9..9a99eeec 100644 --- a/lib/src/widget/toast_animation.dart +++ b/lib/src/widget/toast_animation.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:toastification/src/helper/toast_helper.dart'; import 'package:toastification/toastification.dart'; class ToastTimerAnimationBuilder extends StatefulWidget { diff --git a/lib/toastification.dart b/lib/toastification.dart index 446f21e8..e6c6a62d 100644 --- a/lib/toastification.dart +++ b/lib/toastification.dart @@ -22,10 +22,3 @@ export 'src/widget/built_in/flat/flat.dart'; export 'src/widget/built_in/flat/flat_style.dart'; export 'src/widget/built_in/flat_colored/flat_colored.dart'; export 'src/widget/built_in/flat_colored/flat_colored_style.dart'; - -// helper -export 'src/helper/toast_helper.dart'; - -// TODO(payam): add navigator observer -// TODO(payam): check how you can access to the Theme in the overlay. -// [OverlayPortal]