Implemented insertion of new items into table
This commit is contained in:
parent
0c14da73df
commit
dfbea7cb6c
4 changed files with 1107 additions and 1 deletions
126
lib/widgets/data_input_dialog.dart
Normal file
126
lib/widgets/data_input_dialog.dart
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
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"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue