I have created a class for new Transaction entry form.. where 2 TextField and a Button..
I have created a Function named myf(), I am almost successful but to improve my knowledge and better coding.... I wish to call function like pointer..but it does not work...where I am getting wrong?
I can solve by repeating code inside onsubmit but its not good level job...
POINTER WORKS WITH TEXTBUTTON AND DOES NOT WORK WITH TEXTFIELD ONSUBMIT..THIS IS MY CONFUSION...
here is my coding
import 'package:flutter/material.dart';
class NewTransaction extends StatelessWidget {
final Function func;
NewTransaction(
this.func
);
void myf() {
func(txttitle.text,double.parse(txtamount.text));
}
final txttitle = TextEditingController();
final txtamount = TextEditingController();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0,horizontal: 8.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
elevation: 10,
child: Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
TextField(
controller: txttitle,
onSubmitted: (_){
myf();
},
decoration: InputDecoration(labelText: 'Enter Title'),
),
TextField(
onSubmitted: (_)=>myf, // this one is not working
keyboardType: TextInputType.number,
controller: txtamount,
decoration: InputDecoration(labelText: 'Enter Amount')),
TextButton(
onPressed: myf,
child: Text('Add Record'))
],
),
),
),
);
}
}