126 lines
3.4 KiB
Dart
126 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_fast_forms/flutter_fast_forms.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
Future<String?> showStringInputDialog({String? originalValue}) async {
|
|
final strVal = (originalValue ?? "").obs;
|
|
return await Get.dialog<String>(
|
|
AlertDialog(
|
|
title: const Text("Enter a string"),
|
|
content: TextField(
|
|
controller: TextEditingController(text: originalValue),
|
|
onChanged: (value) {
|
|
strVal.value = value;
|
|
},
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Get.back(result: null);
|
|
},
|
|
child: const Text("Cancel"),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Get.back(result: strVal.value);
|
|
},
|
|
child: const Text("OK"),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<double?> showDoubleInputDialog({double? originalValue}) async {
|
|
final strVal = (originalValue?.toString() ?? "").obs;
|
|
return await Get.dialog<double>(
|
|
AlertDialog(
|
|
title: const Text("Enter a number"),
|
|
content: FastTextField(
|
|
name: "Number",
|
|
initialValue: originalValue?.toString(),
|
|
keyboardType: TextInputType.number,
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return "Please enter a number";
|
|
}
|
|
final parsed = double.tryParse(value);
|
|
if (parsed == null) {
|
|
return "Please enter a valid number";
|
|
}
|
|
return null;
|
|
},
|
|
onChanged: (value) {
|
|
strVal.value = value ?? "";
|
|
},
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Get.back(result: null);
|
|
},
|
|
child: const Text("Cancel"),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
final d = double.tryParse(strVal.value);
|
|
if (d != null) {
|
|
Get.back(result: d);
|
|
} else {
|
|
Get.back(result: null);
|
|
}
|
|
},
|
|
child: const Text("OK"),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<int?> showIntInputDialog({int? originalValue}) async {
|
|
final strVal = (originalValue?.toString() ?? "").obs;
|
|
return await Get.dialog<int>(
|
|
AlertDialog(
|
|
title: const Text("Enter a number"),
|
|
content: FastTextField(
|
|
name: "Number",
|
|
initialValue: originalValue?.toString(),
|
|
keyboardType: TextInputType.number,
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return "Please enter a number";
|
|
}
|
|
final parsed = int.tryParse(value);
|
|
if (parsed == null) {
|
|
return "Please enter a valid number";
|
|
}
|
|
return null;
|
|
},
|
|
onChanged: (value) {
|
|
strVal.value = value ?? "";
|
|
},
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Get.back(result: null);
|
|
},
|
|
child: const Text("Cancel"),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
final i = int.tryParse(strVal.value);
|
|
if (i != null) {
|
|
Get.back(result: i);
|
|
} else {
|
|
Get.back(result: null);
|
|
}
|
|
},
|
|
child: const Text("OK"),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|