92 lines
2.1 KiB
Dart
92 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
enum InputPromptType { Text, Number }
|
|
|
|
/// Prompt which enables the input of data
|
|
class InputPrompt extends StatefulWidget {
|
|
String title;
|
|
String prompt;
|
|
String currentValue;
|
|
InputPromptType type;
|
|
|
|
InputPrompt(
|
|
{super.key,
|
|
required this.title,
|
|
required this.prompt,
|
|
this.currentValue = "",
|
|
required this.type});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return InputPromptState(
|
|
title: title, prompt: prompt, currentValue: currentValue, type: type);
|
|
}
|
|
}
|
|
|
|
class InputPromptState extends State<InputPrompt> {
|
|
String title;
|
|
String prompt;
|
|
String currentValue;
|
|
InputPromptType type;
|
|
TextEditingController textField = TextEditingController();
|
|
|
|
InputPromptState(
|
|
{required this.title,
|
|
required this.prompt,
|
|
required this.currentValue,
|
|
required this.type}) {
|
|
textField.text = currentValue;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(title),
|
|
content: SizedBox(
|
|
width: 200,
|
|
height: 100,
|
|
child: Column(
|
|
children: [
|
|
Text(prompt),
|
|
if (type == InputPromptType.Text)
|
|
TextField(
|
|
controller: textField,
|
|
),
|
|
if (type == InputPromptType.Number)
|
|
TextField(
|
|
controller: textField,
|
|
keyboardType: TextInputType.number,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context, textField.text);
|
|
},
|
|
child: Text("Submit")),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
Navigator.pop(context, "");
|
|
},
|
|
child: Text("Cancel"))
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Alert extends StatelessWidget {
|
|
String title;
|
|
String body;
|
|
|
|
Alert({required this.title, required this.body, super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text(title),
|
|
content: Text(body),
|
|
);
|
|
}
|
|
}
|