Files
syncrow-app/lib/utils/context_extension.dart
Abdullah Alassaf 50aca65c8f Fixed design issues
2024-06-30 15:37:00 +03:00

147 lines
4.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:syncrow_app/features/shared_widgets/bottom_sheet/custom_bottom_sheet.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
extension ContextExtension on BuildContext {
Future<void> goTo(String newRouteName) async {
// go(newRouteName);
await Navigator.pushNamed(this, newRouteName);
}
double get width => MediaQuery.sizeOf(this).width;
double get height => MediaQuery.sizeOf(this).height;
InputDecorationTheme get inputDecoration => Theme.of(this).inputDecorationTheme;
TextStyle get displayLarge => Theme.of(this).textTheme.displayLarge!;
TextStyle get displayMedium => Theme.of(this).textTheme.displayMedium!;
TextStyle get displaySmall => Theme.of(this).textTheme.displaySmall!;
TextStyle get titleLarge => Theme.of(this).textTheme.titleLarge!;
TextStyle get titleMedium => Theme.of(this).textTheme.titleMedium!;
TextStyle get titleSmall => Theme.of(this).textTheme.titleSmall!;
TextStyle get bodyLarge => Theme.of(this).textTheme.bodyLarge!;
TextStyle get bodyMedium => Theme.of(this).textTheme.bodyMedium!;
TextStyle get bodySmall => Theme.of(this).textTheme.bodySmall!;
void customBottomSheet({Widget? child}) {
showModalBottomSheet<void>(
context: this,
isScrollControlled: true,
builder: (BuildContext context) {
return CustomBottomSheet(
child: child,
);
},
);
}
void showCustomSnackbar({required String message, Widget? icon}) {
ScaffoldMessenger.of(this).showSnackBar(
SnackBar(
content: Row(
children: [
Expanded(child: Text(message)),
icon ?? const SizedBox.shrink(),
],
),
),
);
}
void customAlertDialog(
{required Widget alertBody, required String title, required VoidCallback onConfirm}) {
showDialog(
context: this,
builder: (BuildContext context) {
return AlertDialog(
contentPadding: EdgeInsets.zero,
content: Container(
width: MediaQuery.sizeOf(context).width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.only(top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
/// header widget
BodyMedium(
text: title,
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontsManager.extraBold,
),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 50,
),
child: Container(
height: 1,
width: double.infinity,
color: ColorsManager.greyColor,
),
),
/// custom body content
Flexible(child: SingleChildScrollView(child: alertBody)),
/// Footer buttons
Container(
height: 1,
width: double.infinity,
color: ColorsManager.greyColor,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Center(
child: BodyMedium(
text: 'Cancel',
style: context.bodyMedium.copyWith(color: ColorsManager.greyColor),
),
),
),
Container(
height: 50,
width: 1,
color: ColorsManager.greyColor,
),
GestureDetector(
onTap: onConfirm,
child: Center(
child: BodyMedium(
text: 'Confirm',
style: context.bodyMedium
.copyWith(color: ColorsManager.primaryColorWithOpacity),
),
),
),
],
)
],
),
),
);
},
);
}
}