1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- class DialogController extends GetxController {
- var isDialogVisible = false.obs;
- void showErrorDialog() {
- isDialogVisible.value = true;
- }
- Future<String?> showInputDialog({
- required String title,
- required String content,
- String cancelText = "取消",
- String enterText = "确定",
- bool isPassword = false,
- }) {
- final controller = TextEditingController();
-
- return Get.dialog<String>(
- AlertDialog(
- title: Text(title),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(content),
- const SizedBox(height: 10),
- TextField(
- controller: controller,
- obscureText: isPassword,
- decoration: InputDecoration(
- border: const OutlineInputBorder(),
- hintText: isPassword ? "请输入密码" : "请输入",
- ),
- ),
- ],
- ),
- actions: [
- TextButton(
- onPressed: () => Get.back(),
- child: Text(cancelText),
- ),
- TextButton(
- onPressed: () => Get.back(result: controller.text),
- child: Text(enterText),
- ),
- ],
- ),
- );
- }
- Future<bool?> showNormalDialog({
- required String title,
- String? content,
- Widget? child,
- required String cancelText,
- required String enterText,
- bool Function()? validator,
- }) {
- assert(content != null || child != null);
- return Get.dialog(
- AlertDialog(
- title: Text(title),
- content: child ?? Text(content!),
- actions: [
- TextButton(
- onPressed: () => Get.back(result: false),
- child: Text(cancelText),
- ),
- TextButton(
- onPressed: () => Get.back(result: true),
- child: Text(enterText),
- ),
- ],
- ),
- );
- }
- void showToast(String message) {
- Get.showSnackbar(
- GetSnackBar(
- message: message,
- duration: const Duration(seconds: 2),
- ),
- );
- }
- }
|