I'm trying to put a colour behind my IconButtons, using the technique suggested in https://github.com/flutter/flutter/issues/18220
I'm having a problem trying to use it for the back button. My code is complaining
This expression has a type of 'void' so its value can't be used.
And yet I have it typed to VoidCallback. Thoughts?
Thanks.
SliverAppBar(
...
leading: InkyIconButton(
icon: Icons.arrow_back_ios,
pressFunction: Navigator.of(context).pop(),
)
)
class InkyIconButton extends StatelessWidget {
const InkyIconButton({
Key? key,
required this.icon,
required this.pressFunction,
}) : super(key: key);
final IconData icon;
final VoidCallback pressFunction;
@override
Widget build(BuildContext context) {
return Ink(
padding: const EdgeInsets.fromLTRB(8.0, 0, 0, 0),
decoration: const ShapeDecoration(
color: Colors.black,
shape: CircleBorder(),
),
child: IconButton(
padding: EdgeInsets.zero,
onPressed: () => pressFunction,
icon: Icon(icon)),
);
}
}
CodePudding user response:
Try pressFunction(). The parenthesis actually make the function get called.