84 lines
2.3 KiB
Dart
84 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:get/get.dart';
|
||
|
||
extension GetInterfaceExtension on GetInterface {
|
||
Future<bool> confirm({
|
||
required String title,
|
||
required String content,
|
||
String yes = "Да",
|
||
String no = "Нет",
|
||
}) async {
|
||
final result = await Get.defaultDialog(
|
||
title: title,
|
||
content: Text(content),
|
||
textConfirm: yes,
|
||
textCancel: no,
|
||
onConfirm: () => Get.backLegacy(result: true),
|
||
onCancel: () => Get.backLegacy(result: false),
|
||
);
|
||
|
||
return result == true;
|
||
}
|
||
|
||
Future<String?> prompt({
|
||
required String title,
|
||
String message = "",
|
||
String hintText = "",
|
||
String label = "",
|
||
String defaultValue = "",
|
||
String positiveLabel = "ОК",
|
||
String negativeLabel = "Отмена",
|
||
int? maxLength,
|
||
int maxLines = 1,
|
||
Widget? prefix,
|
||
required String? Function(String? x) stringValidator,
|
||
}) async {
|
||
final controller = TextEditingController(text: defaultValue);
|
||
final value = Get.dialog<String>(
|
||
AlertDialog(
|
||
title: Text(title),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
if (message.isNotEmpty)
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: 8),
|
||
child: Text(message),
|
||
),
|
||
TextFormField(
|
||
controller: controller,
|
||
decoration: InputDecoration(
|
||
hintText: hintText,
|
||
filled: true,
|
||
prefix: prefix,
|
||
label: Text(label),
|
||
),
|
||
maxLength: maxLength,
|
||
maxLines: maxLines,
|
||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||
validator: stringValidator,
|
||
)
|
||
],
|
||
),
|
||
actions: [
|
||
ElevatedButton(
|
||
onPressed: () {
|
||
if (stringValidator(controller.value.text) == null) {
|
||
Get.backLegacy(result: controller.value.text);
|
||
}
|
||
},
|
||
child: Text(positiveLabel),
|
||
),
|
||
ElevatedButton(
|
||
onPressed: () => Get.backLegacy(result: null),
|
||
child: Text(negativeLabel),
|
||
),
|
||
],
|
||
),
|
||
barrierDismissible: false,
|
||
useSafeArea: true,
|
||
);
|
||
return value;
|
||
}
|
||
}
|