import 'package:flutter/material.dart';
class Answer extend`enter code here`s StatelessWidget {
// const ({Key? key}) : super(key: key);
final Function sel`enter code here`ectHandler ;
Answer(this.selectHandler);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: RaisedButton(
color: Colors.pink,
child: Text('Pink'),
// textColor: Colors.pink,
onPressed:selectHandler,
),
);
}
}
hey guys please help me to solve this i am having issue in this code @ onPressed:selectHandler
CodePudding user response:
Use voidcallback
import 'package:flutter/material.dart';
class Answer extends StatelessWidget {
const ({Key? key, this.selectHandler}) : super(key: key);
final VoidCallback selectHandler ;
Answer(this.selectHandler);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: RaisedButton(
color: Colors.pink,
child: Text('Pink'),
// textColor: Colors.pink,
onPressed:selectHandler,
),
);
}
}
CodePudding user response:
Use GestureTapCallback. Hope that work for you
import 'package:flutter/material.dart';
class Answer extend StatelessWidget {
// const ({Key? key}) : super(key: key);
final GestureTapCallback selectHandler;
Answer(this.selectHandler);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: RaisedButton(
color: Colors.pink,
child: Text('Pink'),
// textColor: Colors.pink,
onPressed:selectHandler,
),
);
}
}