TF-1915 Show toast message when connected to the internet

(cherry picked from commit a1f466725cf1896cfb43144d41c6806a074e06eb)
This commit is contained in:
dab246
2023-06-08 16:54:12 +07:00
committed by Dat Vu
parent 3100e00c9e
commit 9b5f533579
7 changed files with 117 additions and 87 deletions
+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M12.0029 1.7143L12.0006 1.71429C6.31992 1.71429 1.71484 6.31937 1.71484 12C1.71484 17.6807 6.31992 22.2857 12.0006 22.2857C17.6812 22.2857 22.2863 17.6807 22.2863 12C22.2863 6.32015 17.6825 1.71557 12.0029 1.7143ZM13.9838 20.3408C16.3056 19.7908 18.2621 18.2965 19.4253 16.2857H15.7537C15.4102 17.5959 14.9402 18.6784 14.4653 19.5391C14.3036 19.8323 14.1414 20.0995 13.9838 20.3408ZM16.1023 14.5714H20.1796C20.4345 13.7597 20.572 12.8959 20.572 12C20.572 11.1041 20.4345 10.2403 20.1796 9.42858H16.1023C16.2189 10.2209 16.2863 11.0778 16.2863 12C16.2863 12.9223 16.2189 13.7791 16.1023 14.5714ZM14.3673 9.42858C14.4958 10.2083 14.572 11.0649 14.572 12C14.572 12.9352 14.4958 13.7917 14.3673 14.5714H9.63385C9.50532 13.7917 9.42913 12.9352 9.42913 12C9.42913 11.0649 9.50532 10.2083 9.63385 9.42858H14.3673ZM15.7537 7.71429H19.4253C18.2621 5.70355 16.3056 4.20917 13.9838 3.65917C14.1414 3.90056 14.3036 4.16771 14.4653 4.46094C14.9402 5.32167 15.4102 6.40411 15.7537 7.71429ZM10.0173 3.65917C7.69549 4.20917 5.73899 5.70355 4.57583 7.71429H8.2474C8.59092 6.40411 9.0609 5.32167 9.53578 4.46094C9.69756 4.16771 9.85971 3.90056 10.0173 3.65917ZM10.0274 7.71429C10.3169 6.74454 10.6787 5.93807 11.0368 5.28908C11.3827 4.66216 11.7263 4.18001 12.0006 3.83861C12.2748 4.18001 12.6185 4.66216 12.9643 5.28908C13.3224 5.93807 13.6842 6.74454 13.9737 7.71429H10.0274ZM7.89886 9.42858H3.82153C3.56658 10.2403 3.42913 11.1041 3.42913 12C3.42913 12.8959 3.56658 13.7597 3.82153 14.5714H7.89886C7.78219 13.7791 7.71484 12.9223 7.71484 12C7.71484 11.0778 7.78219 10.2209 7.89886 9.42858ZM8.2474 16.2857H4.57583C5.73899 18.2965 7.69549 19.7908 10.0173 20.3408C9.85971 20.0995 9.69756 19.8323 9.53578 19.5391C9.0609 18.6784 8.59092 17.5959 8.2474 16.2857ZM10.0274 16.2857H13.9737C13.6842 17.2555 13.3224 18.062 12.9643 18.7109C12.6185 19.3379 12.2748 19.82 12.0006 20.1614C11.7263 19.82 11.3827 19.3379 11.0368 18.7109C10.6787 18.062 10.3169 17.2555 10.0274 16.2857Z"
fill="white" />
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

@@ -189,6 +189,7 @@ class ImagePaths {
String get icMenuMailbox => _getImagePath('ic_menu_mailbox.svg');
String get icDelivering => _getImagePath('ic_delivering.svg');
String get icError => _getImagePath('ic_error.svg');
String get icConnectedInternet => _getImagePath('ic_connected_internet.svg');
String _getImagePath(String imageName) {
return AssetsPaths.images + imageName;
+16 -7
View File
@@ -15,7 +15,8 @@ class AppToast {
String message,
{
Color? leadingSVGIconColor,
String? leadingSVGIcon
String? leadingSVGIcon,
Duration? duration,
}
) {
final imagePaths = Get.find<ImagePaths>();
@@ -25,7 +26,8 @@ class AppToast {
backgroundColor: AppColor.toastErrorBackgroundColor,
textColor: Colors.white,
leadingSVGIconColor: leadingSVGIconColor ?? (leadingSVGIcon == null ? Colors.white : null),
leadingSVGIcon: leadingSVGIcon ?? imagePaths.icNotConnection
leadingSVGIcon: leadingSVGIcon ?? imagePaths.icNotConnection,
duration: duration
);
}
@@ -35,6 +37,7 @@ class AppToast {
{
Color? leadingSVGIconColor,
String? leadingSVGIcon,
Duration? duration,
}
) {
final imagePaths = Get.find<ImagePaths>();
@@ -44,7 +47,8 @@ class AppToast {
backgroundColor: AppColor.toastSuccessBackgroundColor,
textColor: Colors.white,
leadingSVGIconColor: leadingSVGIconColor ?? (leadingSVGIcon == null ? Colors.white : null),
leadingSVGIcon: leadingSVGIcon ?? imagePaths.icToastSuccessMessage
leadingSVGIcon: leadingSVGIcon ?? imagePaths.icToastSuccessMessage,
duration: duration
);
}
@@ -54,6 +58,7 @@ class AppToast {
{
Color? leadingSVGIconColor,
String? leadingSVGIcon,
Duration? duration,
}
) {
final imagePaths = Get.find<ImagePaths>();
@@ -63,7 +68,8 @@ class AppToast {
backgroundColor: AppColor.toastWarningBackgroundColor,
textColor: Colors.white,
leadingSVGIconColor: leadingSVGIconColor ?? (leadingSVGIcon == null ? Colors.white : null),
leadingSVGIcon: leadingSVGIcon ?? imagePaths.icInfoCircleOutline
leadingSVGIcon: leadingSVGIcon ?? imagePaths.icInfoCircleOutline,
duration: duration
);
}
@@ -84,7 +90,8 @@ class AppToast {
Color? textActionColor,
TextStyle? textStyle,
EdgeInsets? padding,
TextAlign? textAlign
TextAlign? textAlign,
Duration? duration,
}
) {
final responsiveUtils = Get.find<ResponsiveUtils>();
@@ -160,7 +167,7 @@ class AppToast {
TMailToast.showToast(
message,
context,
width: maxWidth ?? responsiveUtils.getMaxWidthToast(context),
maxWidth: maxWidth ?? responsiveUtils.getMaxWidthToast(context),
toastPosition: ToastPosition.BOTTOM,
textStyle: textStyle ?? TextStyle(
fontSize: 15,
@@ -172,7 +179,9 @@ class AppToast {
leading: leadingWidget,
padding: padding,
textAlign: textAlign,
toastDuration: infinityToast ? null : 3,
toastDuration: infinityToast
? null
: (duration ?? const Duration(seconds: 3)),
);
}
}
@@ -5,62 +5,25 @@ import 'package:core/presentation/views/toast/toast_position.dart';
import 'package:flutter/material.dart';
class TMailToast {
/// text of type [String] display on toast
String? text;
/// defines the duration of time toast display over screen
int? toastDuration;
/// defines the position of toast over the screen
ToastPosition? toastPosition;
/// defines the background color of the toast
Color? backgroundColor;
/// defines the test style of the toast text
TextStyle? textStyle;
/// defines the border radius of the toast
double? toastBorderRadius;
/// defines the border of the toast
Border? border;
/// defines the trailing widget of the toast
Widget? trailing;
/// defines the leading widget of the toast
Widget? leading;
/// defines the size width widget of the toast
double? width;
/// defines the padding widget of the toast
EdgeInsets? padding;
/// defines the align text of the toast
TextAlign? textAlign;
static showToast(
text,
BuildContext context, {
toastDuration,
toastPosition,
backgroundColor,
textStyle = const TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.normal
),
toastBorderRadius = 10.0,
border,
trailing,
leading,
width,
padding,
textAlign
}) {
assert(text != null);
String text,
BuildContext context, {
Duration? toastDuration,
ToastPosition? toastPosition,
Color? backgroundColor,
TextStyle textStyle = const TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.normal
),
double toastBorderRadius = 10.0,
Border? border,
Widget? trailing,
Widget? leading,
double maxWidth = 424,
EdgeInsets? padding,
TextAlign? textAlign
}) {
ToastView.dismiss();
ToastView.createView(
text,
@@ -72,7 +35,7 @@ class TMailToast {
border,
trailing,
leading,
width,
maxWidth,
padding,
textAlign,
toastDuration: toastDuration,
@@ -99,18 +62,17 @@ class ToastView {
Border? border,
Widget? trailing,
Widget? leading,
double? width,
double maxWidth,
EdgeInsets? padding,
TextAlign? textAlign,
{int? toastDuration}
{Duration? toastDuration}
) async {
overlayState = Overlay.of(context, rootOverlay: false);
final Widget child = Center(
child: Material(
color: Colors.transparent,
child: Container(
width: width,
constraints: BoxConstraints(maxWidth: maxWidth),
decoration: BoxDecoration(
color: backgroundColor ?? Colors.white,
borderRadius: BorderRadius.circular(toastBorderRadius),
@@ -126,8 +88,7 @@ class ToastView {
offset: Offset.zero),
]
),
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: padding ?? const EdgeInsets.all(12),
padding: padding ?? const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: trailing == null && leading == null
? Text(
text,
@@ -140,21 +101,39 @@ class ToastView {
textAlign: textAlign
)
: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
if (leading != null) leading,
Expanded(child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
text,
style: textStyle ?? const TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.normal
if (trailing != null)
Expanded(child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
text,
style: textStyle ?? const TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.normal
),
textAlign: textAlign
)
))
else
Container(
constraints: BoxConstraints(maxWidth: _getMaxWidthTitleByLeadingTrailingSize(
currentMaxWidth: maxWidth,
leading: leading
)),
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
text,
style: textStyle ?? const TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.normal
),
textAlign: textAlign
),
textAlign: textAlign
)
)),
),
if (trailing != null) trailing
],
),
@@ -166,7 +145,7 @@ class ToastView {
_overlayEntry = OverlayEntry(builder: (context) =>
_showWidgetBasedOnPosition(
toastDuration != null
? ToastCard(child, Duration(seconds: toastDuration))
? ToastCard(child, toastDuration)
: child,
toastPosition,
)
@@ -175,22 +154,29 @@ class ToastView {
_isVisible = true;
overlayState!.insert(_overlayEntry!);
if (toastDuration != null) {
await Future.delayed(Duration(seconds: toastDuration));
await Future.delayed(toastDuration);
await dismiss();
}
}
static double _getMaxWidthTitleByLeadingTrailingSize({
required double currentMaxWidth,
Widget? leading
}) {
return leading == null ? currentMaxWidth : currentMaxWidth - 90;
}
static Positioned _showWidgetBasedOnPosition(
Widget child,
ToastPosition? toastPosition
) {
switch (toastPosition) {
case ToastPosition.BOTTOM:
return Positioned(bottom: 60, left: 18, right: 18, child: child);
return Positioned(bottom: 80, left: 18, right: 18, child: child);
case ToastPosition.BOTTOM_LEFT:
return Positioned(bottom: 60, left: 18, child: child);
return Positioned(bottom: 80, left: 18, child: child);
case ToastPosition.BOTTOM_RIGHT:
return Positioned(bottom: 60, right: 18, child: child);
return Positioned(bottom: 80, right: 18, child: child);
case ToastPosition.CENTER:
return Positioned(top: 60, bottom: 60, left: 18, right: 18, child: child);
case ToastPosition.CENTER_LEFT:
@@ -58,6 +58,8 @@ class NetworkConnectionController extends BaseController {
_setNetworkConnectivityState(result);
if (_isEnableShowToastDisconnection && !isNetworkConnectionAvailable()) {
_showToastLostConnection();
} else if (isNetworkConnectionAvailable()) {
_showToastConnectedToTheNetwork();
} else {
ToastView.dismiss();
}
@@ -94,4 +96,18 @@ class NetworkConnectionController extends BaseController {
);
}
}
void _showToastConnectedToTheNetwork() {
if (currentContext != null && currentOverlayContext != null) {
_appToast.showToastMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).connectedToTheInternet,
leadingSVGIcon: _imagePaths.icConnectedInternet,
backgroundColor: AppColor.primaryColor,
textColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
duration: const Duration(seconds: 5)
);
}
}
}
+7 -1
View File
@@ -1,5 +1,5 @@
{
"@@last_modified": "2023-06-08T15:15:04.969556",
"@@last_modified": "2023-06-08T16:53:26.593398",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
@@ -2899,5 +2899,11 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"connectedToTheInternet": "Connected to the internet",
"@connectedToTheInternet": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
@@ -2988,4 +2988,11 @@ class AppLocalizations {
name: 'error',
);
}
String get connectedToTheInternet {
return Intl.message(
'Connected to the internet',
name: 'connectedToTheInternet'
);
}
}