import 'package:flutter/material.dart'; import 'package:fmassive/home_page.dart'; class EditGymSetPage extends StatefulWidget { final GymSet gymSet; EditGymSetPage({required this.gymSet}); @override _EditGymSetPageState createState() => _EditGymSetPageState(); } class _EditGymSetPageState extends State { final TextEditingController _nameController = TextEditingController(); final TextEditingController _repsController = TextEditingController(); final TextEditingController _weightController = TextEditingController(); late GymSet _editedGymSet; @override void initState() { super.initState(); // Initialize the edited GymSet object with the values from the input GymSet object _editedGymSet = GymSet( name: widget.gymSet.name, reps: widget.gymSet.reps, weight: widget.gymSet.weight, created: DateTime.now()); // Set the text controller values _nameController.text = _editedGymSet.name; _repsController.text = _editedGymSet.reps.toString(); _weightController.text = _editedGymSet.weight.toString(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Edit Gym Set'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ TextFormField( controller: _nameController, decoration: const InputDecoration(labelText: 'Name'), onChanged: (value) { setState(() { _editedGymSet.name = value; }); }, ), TextFormField( controller: _repsController, decoration: const InputDecoration(labelText: 'Reps'), keyboardType: TextInputType.number, onChanged: (value) { setState(() { _editedGymSet.reps = int.tryParse(value) ?? 0; }); }, ), TextFormField( controller: _weightController, decoration: const InputDecoration(labelText: 'Weight (kg)'), keyboardType: TextInputType.number, onChanged: (value) { setState(() { _editedGymSet.weight = int.tryParse(value) ?? 0; }); }, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.pop(context, _editedGymSet); }, child: const Icon(Icons.check), ), ); } }