Solian/lib/exts.dart

70 lines
1.7 KiB
Dart
Raw Permalink Normal View History

2024-05-19 16:08:20 +00:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
extension SolianExtenions on BuildContext {
2024-07-31 18:10:57 +00:00
void showSnackbar(String content, {SnackBarAction? action}) {
2024-05-19 16:08:20 +00:00
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
content: Text(content),
2024-07-31 18:10:57 +00:00
action: action,
2024-05-19 16:08:20 +00:00
));
}
2024-06-29 13:03:15 +00:00
void clearSnackbar() {
ScaffoldMessenger.of(this).clearSnackBars();
}
2024-06-30 10:03:02 +00:00
Future<void> showModalDialog(String title, desc) {
return showDialog<void>(
useRootNavigator: true,
context: this,
builder: (ctx) => AlertDialog(
title: Text(title),
content: Text(desc),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: Text('okay'.tr),
)
],
),
);
}
2024-08-02 17:14:42 +00:00
Future<void> showInfoDialog(String title, body) {
return showDialog<void>(
useRootNavigator: true,
context: this,
builder: (ctx) => AlertDialog(
title: Text(title),
content: Text(body),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: Text('okay'.tr),
)
],
),
);
}
2024-05-19 16:08:20 +00:00
Future<void> showErrorDialog(dynamic exception) {
var stack = StackTrace.current;
var stackTrace = '$stack';
2024-05-19 16:08:20 +00:00
return showDialog<void>(
2024-06-01 12:18:25 +00:00
useRootNavigator: true,
2024-05-19 16:08:20 +00:00
context: this,
builder: (ctx) => AlertDialog(
title: Text('errorHappened'.tr),
content: Text('${exception.toString().capitalize!}\n\nStack Trace: $stackTrace'),
2024-05-19 16:08:20 +00:00
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: Text('okay'.tr),
)
],
),
);
}
}