Auto focus and select text for edit_set
This commit is contained in:
parent
4d3de751f3
commit
a8b6c9f8a3
|
@ -18,6 +18,8 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||
final TextEditingController _repsController = TextEditingController();
|
||||
final TextEditingController _weightController = TextEditingController();
|
||||
late GymSetsCompanion gymSet;
|
||||
final nameNode = FocusNode();
|
||||
final repsNode = FocusNode();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -26,6 +28,17 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||
_nameController.text = gymSet.name.value;
|
||||
_repsController.text = gymSet.reps.value.toString();
|
||||
_weightController.text = gymSet.weight.value.toString();
|
||||
if (gymSet.id.present)
|
||||
repsNode.requestFocus();
|
||||
else
|
||||
nameNode.requestFocus();
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
nameNode.dispose();
|
||||
repsNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -49,7 +62,12 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||
children: [
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
focusNode: nameNode,
|
||||
decoration: const InputDecoration(labelText: 'Name'),
|
||||
onTap: () {
|
||||
_nameController.selection = TextSelection(
|
||||
baseOffset: 0, extentOffset: _nameController.text.length);
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
gymSet = gymSet.copyWith(name: Value(value));
|
||||
|
@ -58,6 +76,11 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||
),
|
||||
TextFormField(
|
||||
controller: _repsController,
|
||||
focusNode: repsNode,
|
||||
onTap: () {
|
||||
_repsController.selection = TextSelection(
|
||||
baseOffset: 0, extentOffset: _repsController.text.length);
|
||||
},
|
||||
decoration: const InputDecoration(labelText: 'Reps'),
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
|
@ -71,6 +94,10 @@ class _EditGymSetPageState extends State<EditGymSetPage> {
|
|||
controller: _weightController,
|
||||
decoration: const InputDecoration(labelText: 'Weight (kg)'),
|
||||
keyboardType: TextInputType.number,
|
||||
onTap: () {
|
||||
_weightController.selection = TextSelection(
|
||||
baseOffset: 0, extentOffset: _weightController.text.length);
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
gymSet =
|
||||
|
|
Loading…
Reference in New Issue
Block a user