Made the UI fancier but still unable to get the controller to work.

This commit is contained in:
Hyperling 2025-01-30 20:48:30 -07:00
parent b07a8f9c0a
commit 3b7313ca10

View File

@ -7,9 +7,23 @@ void main() {
runApp(const MainApp()); runApp(const MainApp());
} }
class MainApp extends StatelessWidget { class MainApp extends StatefulWidget {
const MainApp({super.key}); const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
final nameFieldController = TextEditingController();
@override
void dispose() {
// Clean up the controller when the widget is disposed.
nameFieldController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const inputWidth = 400.0; const inputWidth = 400.0;
@ -20,11 +34,10 @@ class MainApp extends StatelessWidget {
DropdownMenuEntry(value: Recurrence.weekly, label: "Weekly"), DropdownMenuEntry(value: Recurrence.weekly, label: "Weekly"),
DropdownMenuEntry(value: Recurrence.biweekly, label: "Biweekly"), DropdownMenuEntry(value: Recurrence.biweekly, label: "Biweekly"),
DropdownMenuEntry(value: Recurrence.montly, label: "Monthly"), DropdownMenuEntry(value: Recurrence.montly, label: "Monthly"),
DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly") DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"),
DropdownMenuEntry(value: null, label: ""),
]; ];
var cost;
return const MaterialApp( return const MaterialApp(
home: Scaffold( home: Scaffold(
body: Center( body: Center(
@ -35,29 +48,30 @@ class MainApp extends StatelessWidget {
height: inputHeight, height: inputHeight,
child: TextField( child: TextField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: InputDecoration(hintText: "Expense Name"), decoration: InputDecoration(labelText: "Name", hintText: "Example: Red Pocket Phone Bill", ),
// https://docs.flutter.dev/cookbook/forms/retrieve-input // https://docs.flutter.dev/cookbook/forms/retrieve-input
//controller: nameFieldController,
)), )),
SizedBox( SizedBox(
width: inputWidth, width: inputWidth,
height: inputHeight, height: inputHeight,
child: TextField( child: TextField(
keyboardType: TextInputType.numberWithOptions(decimal: true), keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(hintText: "Expense Cost"), decoration: InputDecoration(labelText: "Cost", hintText: "Example: 10.00"),
), ),
), ),
DropdownMenu( DropdownMenu(
dropdownMenuEntries: recurrenceValues, dropdownMenuEntries: recurrenceValues,
hintText: "Recurrence",
width: inputWidth, width: inputWidth,
label: Text("Recurrence"),
hintText: "Example: Monthly",
), ),
SizedBox( SizedBox(
width: inputWidth, width: inputWidth,
height: inputHeight, height: inputHeight,
child: TextField( child: TextField(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
decoration: InputDecoration(hintText: "Expense Description"), decoration: InputDecoration(labelText: "Description", hintText: "Example: 1GB data with unlimited talk & text."),
)), )),
]), ]),
), ),
@ -67,13 +81,7 @@ class MainApp extends StatelessWidget {
} }
// https://www.tutorialspoint.com/dart_programming/dart_programming_enumeration.htm // https://www.tutorialspoint.com/dart_programming/dart_programming_enumeration.htm
enum Recurrence { enum Recurrence { daily, weekly, biweekly, montly, yearly }
daily,
weekly,
biweekly,
montly,
yearly
}
class Expense { class Expense {
String name; String name;