didvan-app/lib/utils/action_sheet.dart

192 lines
6.3 KiB
Dart

import 'dart:async';
import 'package:another_flushbar/flushbar.dart';
import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.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:flutter/services.dart';
import 'package:rive/rive.dart';
class ActionSheetUtils {
static late BuildContext context;
static Future<void> showLogoLoadingIndicator() async {
await showDialog(
context: context,
builder: (context) =>
// _customSystemOverlayStyle(
// child:
Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width / 3,
),
child: RiveAnimation.asset(Assets.logoLoadingAnimation),
// ),
),
);
}
static AnnotatedRegion _customSystemOverlayStyle({required Widget child}) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: DesignConfig.systemUiOverlayStyle.copyWith(
systemNavigationBarColor: DesignConfig
.systemUiOverlayStyle.systemNavigationBarColor!
.withBlue(20),
),
child: child,
);
}
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;
}
await Flushbar(
margin: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
borderColor: foregroundColor,
backgroundColor: backgroundColor,
borderRadius: DesignConfig.mediumBorderRadius,
padding: const EdgeInsets.symmetric(vertical: 16),
icon: Icon(
DidvanIcons.info_circle_solid,
color: foregroundColor,
),
shouldIconPulse: true,
dismissDirection: FlushbarDismissDirection.HORIZONTAL,
flushbarPosition: FlushbarPosition.BOTTOM,
messageText: StatefulBuilder(builder: (context, setState) {
if (isInit) {
Future.delayed(Duration.zero, () {
setState(() {});
isInit = false;
});
}
return Column(
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,
),
],
);
}),
duration: const Duration(seconds: 2),
boxShadows: [
BoxShadow(color: Theme.of(context).colorScheme.cardBorder),
],
).show(context);
}
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),
Row(
children: [
if (data.hasDismissButton)
Expanded(
child: DidvanButton(
onPressed: () {
Navigator.of(context).pop();
data.onDismissed?.call();
},
title: data.dismissTitle ?? 'بازگشت',
style: ButtonStyleMode.flat,
),
),
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();
}
}