you can do like this.
NavigationDemo.dart
class NavigationDemo extends StatefulWidget {
const NavigationDemo({Key? key}) : super(key: key);
@override
_NavigationDemoState createState() => _NavigationDemoState();
}
class _NavigationDemoState extends State<NavigationDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>DemoText("Text1")));
},
child: Text('Text1',style: TextStyle(fontSize: 20))),
SizedBox(width: 10,),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=> DemoText("Text2")));
},
child: Text('Text2',style: TextStyle(fontSize: 20))),
SizedBox(width: 10,),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=> DemoText("Text3")));
},
child: Text('Text3',style: TextStyle(fontSize: 20))),
SizedBox(width: 10,),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=> DemoText("Text4")));;
},
child: Text('Text4',style: TextStyle(fontSize: 20))),
SizedBox(width: 10,),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=> DemoText("Text5")));;
},
child: Text('Text5',style: TextStyle(fontSize: 20))),
],
),
),
);
}
}
DemoText.dart
class DemoText extends StatefulWidget {
String text;
DemoText(this.text);
@override
_DemoTextState createState() {
return _DemoTextState();
}
}
class _DemoTextState extends State<DemoText> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(widget.text,style: TextStyle(fontSize: 20),),
),
);
}
}
This is just example you can refer this.