import
'package:flutter/material.dart'
;
void
main() {
runApp(
const
MyApp());
}
class
MyApp extends StatelessWidget {
const
MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return
MaterialApp(
title:
'Flutter Demo'
,
theme: ThemeData(
primarySwatch: Colors.green,
),
home:
const
MyHomePage(),
);
}
}
class
MyHomePage extends StatefulWidget {
const
MyHomePage({ Key? key }) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class
_MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return
Center(
child: ElevatedButton(
onPressed: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context){
return
const
NextPage();
}));
},
child:
const
Text(
'Next Page'
),
),
);
}
}
class
NextPage extends StatelessWidget {
const
NextPage({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
return
WillPopScope(
child: Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
leading: IconButton(onPressed: () {
Navigator.of(context).pop();
},
icon:
const
Icon(Icons.arrow_back_ios_new),
),
title:
const
Text(
'Next Page'
),
),
body:
const
Center(),
),
onWillPop: () async {
return
false
;
}
);
}
}