I need to insert onpressed()function (navigator push to other page) on the icons bellow:
Column buildButtonColumn(IconData icon, String label) {
Color color = Theme.of(context).primaryColor;
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, color: color),
Container(
margin: const EdgeInsets.only(top: 8.0),
child: Text(
label,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
color: color,
),
),
),
],
);
}
Widget buttonSection = Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildButtonColumn(Icons.call, 'CALL'),
buildButtonColumn(Icons.near_me, 'ROUTE'),
buildButtonColumn(Icons.share, 'SHARE'),
],
),
);
To execute a function when button is pressed, use onPressed () property of the button. Following is a sample code snippet to execute a function when RaisedButton is pressed. In this example Flutter Application, we shall take a RaisedButton and execute a function when the button is pressed.
Terminology: In Flutter, screens and pages are called routes . The remainder of this recipe refers to routes. In Android, a route is equivalent to an Activity.
Most apps contain several screens for displaying different types of information. For example, an app might have a screen that displays products. When the user taps the image of a product, a new screen displays details about the product. Terminology: In Flutter, screens and pages are called routes .
In this tutorial, we will learn how to execute a function when user pressed a button. To execute a function when button is pressed, use onPressed () property of the button. Following is a sample code snippet to execute a function when RaisedButton is pressed.
You can make use of an IconButton
widget for this.
IconButton(
icon: Icon(Icons.info),
onPressed: (){
// Do something
},
)
of you can make use of GestureDetector
GestureDetector(
onTap: () {
//Do something
},
child: icon: Icon(Icons.info),
)
EDIT:
With a little modification to the codes pasted below. Change buildButtonColumn tho this:
buildButtonColumn(icon, label, onTap) {
Color color = Theme.of(context).primaryColor;
return GestureDetector(
onTap: onTap,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, color: color),
Container(
margin: const EdgeInsets.only(top: 8.0),
child: Text(
label,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
color: color,
),
),
),
],
),
);
}
and For button Section, use this.
Widget buttonSection = Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildButtonColumn(Icons.call, 'CALL', (){
print('call');
}),
buildButtonColumn(Icons.near_me, 'ROUTE', (){
print('route');
}),
buildButtonColumn(Icons.share, 'SHARE', (){
print('share');
}),
],
),
);
You can use this:
GestureDetector buildButtonColumn(IconData icon, String label){
onTap(){
print("Pressed");
}
Color color = Theme.of(context).primaryColor;
return GestureDetector(
onTap: onTap,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, color: color),
Container(
margin: const EdgeInsets.only(top: 8.0),
child: Text(
label,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
color: color,
),
),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: Scaffold(
body: Center(
child:Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildButtonColumn(Icons.call, 'CALL'),
buildButtonColumn(Icons.near_me, 'ROUTE'),
buildButtonColumn(Icons.share, 'SHARE'),
],
),
),
),
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With