In this article you will know how to use the inkwell class to navigate by clicking images.
This is the code of main.dart file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Inkwell App"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
//mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Example of inkwell widget"),
InkWell(
child: Image.asset("image/colors.jpg"),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => NewPage()));
},
)
],
),
),
);
}
}
class NewPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Next Page"),
),
body: Text("."),
);
}
}