163 lines
4.2 KiB
Dart
163 lines
4.2 KiB
Dart
// Flutter imports:
|
|
import 'package:flutter/material.dart';
|
|
|
|
// Package imports:
|
|
import 'package:oktoast/oktoast.dart' show dismissAllToast;
|
|
import 'package:remever/common/resources.dart';
|
|
import 'package:remever/common/widgets/typography.dart';
|
|
import 'package:remever/common/widgets/wspace.dart';
|
|
import 'package:remever/components/extensions/context.dart';
|
|
|
|
// Project imports:
|
|
import 'package:remever/gen/assets.gen.dart';
|
|
|
|
enum ToastType {
|
|
///
|
|
/// Стандартный тост
|
|
///
|
|
DEFAULT,
|
|
|
|
///
|
|
/// Закрываемый вручную тост
|
|
///
|
|
DISMISSIBLE,
|
|
}
|
|
|
|
class InfoToast extends StatelessWidget {
|
|
///
|
|
/// Виджет отображающийся при использовании [Toast.show]
|
|
///
|
|
const InfoToast({required this.child, super.key})
|
|
: toastType = ToastType.DEFAULT,
|
|
message = '',
|
|
type = null,
|
|
textColor = null,
|
|
bgColor = null;
|
|
|
|
const InfoToast.dismissible({
|
|
required this.message,
|
|
this.type,
|
|
this.textColor,
|
|
this.bgColor,
|
|
super.key,
|
|
}) : toastType = ToastType.DISMISSIBLE,
|
|
child = const SizedBox();
|
|
|
|
/// Сообщение в [ToastType.DISMISSIBLE]
|
|
final String message;
|
|
|
|
/// Сообщение в [ToastType.DEFAULT]
|
|
final Widget child;
|
|
|
|
/// Тип тоста
|
|
final ToastType toastType;
|
|
|
|
/// Тип типографии
|
|
final TypographyType? type;
|
|
|
|
/// Цвет текста
|
|
final Color? textColor;
|
|
|
|
/// Фоновый цвет
|
|
final Color? bgColor;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return switch (toastType) {
|
|
ToastType.DEFAULT => _Toast(child: child),
|
|
ToastType.DISMISSIBLE => _DismissibleToast(
|
|
message: message,
|
|
type: type,
|
|
textColor: textColor,
|
|
bgColor: bgColor,
|
|
),
|
|
};
|
|
}
|
|
}
|
|
|
|
class _DismissibleToast extends StatelessWidget {
|
|
const _DismissibleToast({
|
|
required this.message,
|
|
this.type,
|
|
this.textColor,
|
|
this.bgColor,
|
|
});
|
|
|
|
final String message;
|
|
final TypographyType? type;
|
|
final Color? textColor;
|
|
final Color? bgColor;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Material(
|
|
child: SizedBox(
|
|
width: MediaQuery.sizeOf(context).width * 0.9,
|
|
// height: 60.h,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(minHeight: 60.h),
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)).r,
|
|
color: bgColor ?? AppColors.white,
|
|
border: Border.all(color: AppColors.gray, width: 0.5.w),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12).r,
|
|
child: Row(
|
|
children: <Widget>[
|
|
Assets.icons.typeDanger.image(height: 24.h, width: 24.w),
|
|
const WSpace(8),
|
|
Flexible(
|
|
fit: FlexFit.tight,
|
|
child: AppTypography(
|
|
message,
|
|
type: type,
|
|
color: textColor ?? AppColors.white,
|
|
textAlign: TextAlign.start,
|
|
maxLines: 3,
|
|
),
|
|
),
|
|
InkWell(
|
|
onTap: dismissAllToast,
|
|
child: SizedBox.square(
|
|
dimension: 24.r,
|
|
child: const DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppColors.gray_bg,
|
|
),
|
|
child: Icon(Icons.close, color: AppColors.disabled),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Toast extends StatelessWidget {
|
|
const _Toast({required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Material(
|
|
child: SizedBox(
|
|
height: 40,
|
|
width: MediaQuery.sizeOf(context).width * 0.6,
|
|
child: ClipRRect(
|
|
borderRadius: const BorderRadius.all(Radius.circular(15)).r,
|
|
child: child,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|