didvan-app/lib/utils/action_sheet.dart

164 lines
5.4 KiB
Dart

import 'dart:async';
import 'package:bot_toast/bot_toast.dart';
import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/assets.dart';
import 'package:didvan/models/enums.dart';
import 'package:didvan/models/view/action_sheet_data.dart';
import 'package:didvan/models/view/alert_data.dart';
import 'package:didvan/widgets/didvan/button.dart';
import 'package:didvan/widgets/didvan/text.dart';
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class ActionSheetUtils {
static late BuildContext context;
static Future<void> showLogoLoadingIndicator() async {
await showDialog(
context: context,
builder: (context) => Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width / 3,
),
child: RiveAnimation.asset(Assets.logoLoadingAnimation),
),
);
}
static Future<void> showAlert(AlertData alertData) async {
bool isInit = true;
Color backgroundColor;
Color foregroundColor;
switch (alertData.aLertType) {
case ALertType.info:
backgroundColor = Theme.of(context).colorScheme.focused;
foregroundColor = Theme.of(context).colorScheme.focusedBorder;
break;
case ALertType.success:
backgroundColor = Theme.of(context).colorScheme.successBack;
foregroundColor = Theme.of(context).colorScheme.success;
break;
case ALertType.error:
backgroundColor = Theme.of(context).colorScheme.errorBack;
foregroundColor = Theme.of(context).colorScheme.error;
break;
}
BotToast.showNotification(
backgroundColor: backgroundColor,
title: (cancelFunc) => StatefulBuilder(
builder: (context, setState) {
if (isInit) {
Future.delayed(Duration.zero, () {
setState(() {});
isInit = false;
});
}
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DidvanText(alertData.message, color: foregroundColor),
AnimatedContainer(
duration: const Duration(seconds: 2),
width: isInit ? MediaQuery.of(context).size.width - 32 : 0,
height: 2,
color: foregroundColor,
),
],
);
},
),
);
}
static Future<void> showBottomSheet({required ActionSheetData data}) async {
await showModalBottomSheet(
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
builder: (context) => Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(
10,
),
),
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
height: 3,
width: 50,
color: Theme.of(context).colorScheme.hint,
),
),
const SizedBox(height: 8),
Row(
children: [
if (data.titleIcon != null)
Icon(
data.titleIcon,
color: data.titleColor ??
Theme.of(context).colorScheme.title,
),
if (data.titleIcon != null) const SizedBox(width: 8),
DidvanText(
data.title,
style: Theme.of(context).textTheme.subtitle1,
color:
data.titleColor ?? Theme.of(context).colorScheme.title,
)
],
),
const SizedBox(height: 28),
data.content,
const SizedBox(height: 28),
if (!data.withoutButtonMode)
Row(
children: [
if (data.hasDismissButton)
Expanded(
child: DidvanButton(
onPressed: () {
Navigator.of(context).pop();
data.onDismissed?.call();
},
title: data.dismissTitle ?? 'بازگشت',
style: ButtonStyleMode.secondary,
),
),
if (data.hasDismissButton) const SizedBox(width: 20),
Expanded(
flex: data.smallDismissButton ? 2 : 1,
child: DidvanButton(
style: ButtonStyleMode.primary,
onPressed: () {
Navigator.of(context).pop();
data.onConfirmed?.call();
},
title: data.confrimTitle ?? 'تایید',
),
),
],
),
],
),
),
),
);
}
static void pop() {
DesignConfig.updateSystemUiOverlayStyle();
Navigator.of(context).pop();
}
}