From aaa95bd3a6fab25335c16c9fe8d359c8fe52e50e Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 1 Feb 2025 03:14:34 -0700 Subject: [PATCH] Break the form into its own widget, since eventually it'll likely be a pop-up. --- lib/main.dart | 116 +++++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index b7cd0ac..5656221 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,28 +2,42 @@ // - https://flutter.dev/docs/cookbook/forms/validation import 'package:flutter/material.dart'; +//import 'package:provider/provider.dart'; void main() { runApp(const MainApp()); } -class MainApp extends StatefulWidget { +class MainApp extends StatelessWidget { const MainApp({super.key}); @override - State createState() => _MainAppState(); + Widget build(BuildContext context) { + + return MaterialApp( + title: 'Recurring Expense Tracker', + theme: ThemeData( + useMaterial3: true, + colorScheme: ColorScheme.fromSeed(seedColor: Colors.green), + ), + home: Scaffold( + body: ExpenseInputForm(), + //floatingActionButton: IconButton(onPressed: appState.newExpense(), icon: Icon(Icons.add)), + ), + ); + } } -class _MainAppState extends State { - final nameFieldController = TextEditingController(); +class ExpenseInputForm extends StatefulWidget { + const ExpenseInputForm({ + super.key, + }); @override - void dispose() { - // Clean up the controller when the widget is disposed. - nameFieldController.dispose(); - super.dispose(); - } + State createState() => _ExpenseInputFormState(); +} +class _ExpenseInputFormState extends State { @override Widget build(BuildContext context) { const inputWidth = 400.0; @@ -37,52 +51,48 @@ class _MainAppState extends State { DropdownMenuEntry(value: Recurrence.yearly, label: "Yearly"), ]; - return const MaterialApp( - home: Scaffold( - body: Center( - child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [ - Text('Input an expense below!'), - SizedBox( - width: inputWidth, - height: inputHeight, - child: TextField( - keyboardType: TextInputType.text, - decoration: InputDecoration( - labelText: "Name", - hintText: "Example: Red Pocket Phone Bill", - ), - // https://docs.flutter.dev/cookbook/forms/retrieve-input - //controller: nameFieldController, - )), - SizedBox( - width: inputWidth, - height: inputHeight, - child: TextField( - keyboardType: TextInputType.numberWithOptions(decimal: true), - decoration: InputDecoration( - labelText: "Cost", hintText: "Example: 10.00"), + return Center( + child: Column(mainAxisSize: MainAxisSize.min, spacing: 10, children: [ + Text('Input an expense below!'), + SizedBox( + width: inputWidth, + height: inputHeight, + child: TextField( + keyboardType: TextInputType.text, + decoration: InputDecoration( + labelText: "Name", + hintText: "Example: Red Pocket Phone Bill", ), - ), - DropdownMenu( - dropdownMenuEntries: recurrenceValues, - width: inputWidth, - label: Text("Recurrence"), - hintText: "Example: Monthly", - ), - SizedBox( - width: inputWidth, - height: inputHeight, - child: TextField( - keyboardType: TextInputType.text, - decoration: InputDecoration( - labelText: "Description", - hintText: - "Example: 1GB data with unlimited talk & text." - ), - )), - ]), + // https://docs.flutter.dev/cookbook/forms/retrieve-input + //controller: nameFieldController, + )), + SizedBox( + width: inputWidth, + height: inputHeight, + child: TextField( + keyboardType: TextInputType.numberWithOptions(decimal: true), + decoration: InputDecoration( + labelText: "Cost", hintText: "Example: 10.00"), + ), ), - ), + DropdownMenu( + dropdownMenuEntries: recurrenceValues, + width: inputWidth, + label: Text("Recurrence"), + hintText: "Example: Monthly", + ), + SizedBox( + width: inputWidth, + height: inputHeight, + child: TextField( + keyboardType: TextInputType.text, + decoration: InputDecoration( + labelText: "Description", + hintText: + "Example: 1GB data with unlimited talk & text." + ), + )), + ]), ); } }