Skip to content

Commit

Permalink
add dart doc
Browse files Browse the repository at this point in the history
  • Loading branch information
payam-zahedi committed Sep 25, 2023
1 parent b498a95 commit 97288e7
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 25 deletions.
26 changes: 21 additions & 5 deletions lib/src/core/toastification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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),
/// );
/// ```
Expand Down Expand Up @@ -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),
/// );
/// ```
Expand Down Expand Up @@ -84,8 +86,14 @@ class Toastification {
final Map<Alignment, ToastificationManager> _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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 :
///
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion lib/src/core/toastification_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion lib/src/core/toastification_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}

Expand Down Expand Up @@ -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<ToastTimeStatus> _timeStatus =
ValueNotifier(ToastTimeStatus.init);

Expand Down
10 changes: 3 additions & 7 deletions lib/src/core/toastification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ class ToastificationManager {
/// if the list is empty, the overlay entry will be removed
final List<ToastificationItem> _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,
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 22 additions & 4 deletions lib/src/widget/built_in/built_in.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
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,
flatColored,
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;

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/src/widget/built_in/built_in_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions lib/src/widget/built_in/built_in_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const lowModeShadow = [
spreadRadius: 0,
)
];

const highModeShadow = [
BoxShadow(
color: Color(0x14000000),
Expand Down
1 change: 1 addition & 0 deletions lib/src/widget/built_in/filled/filled_style.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/src/widget/built_in/flat/flat_style.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/src/widget/built_in/minimal/minimal_style.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/src/widget/toast_animation.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions lib/toastification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 97288e7

Please sign in to comment.