For the sake of this question I have simplified my case here. I want to reuse a button widget which opens up a textfield dialog. If the button receive String data value then use text keyboard and if data type is int then use number keyboard. How can I do that? Here is my code
my screen
class MyScreen1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: ReuseButton(value: 'pp'), //passing String value
);
}
}
reusable button
class ReuseButton extends StatelessWidget {
final dynamic value; // receiving unspecified data type
const ReuseButton({this.value});
@override
Widget build(BuildContext context) {
return FlatButton(
child: Text('Enter Value'),
onPressed: () async {
String s = await textFieldDialog(
context: context,
initialValue: '',
keyboardType: TextInputType.numberWithOptions(
decimal: true), //here to do comparison
title: 'Equal to');
print(s);
},
);
}
}
I have already tried to make a model which is a simple class
class SpecVal<T> {
T data;
SpecVal(this.data);
}
and then pass this data in my screen to the button widget
ReuseButton(value: SpecVal<String>('some value'))
But then I was having problem to find out what data type SpecVal is using in the button widget to do comparison