ProfilePage.dart
import 'package:flutter/material.dart';
import 'package:flutter03/widgets/menu.dart';
class ProfilePage extends StatefulWidget {
const ProfilePage({Key? key}) : super(key: key);
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Menu(),
appBar: AppBar(
title: Text('ProfilePage'),
)
);
}
}
SettingPage.dart
import 'package:flutter/material.dart';
import 'package:flutter03/widgets/menu.dart';
class SettingPage extends StatefulWidget {
const SettingPage({Key? key}) : super(key: key);
@override
_SettingPageState createState() => _SettingPageState();
}
class _SettingPageState extends State<SettingPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Menu(),
appBar: AppBar(
title: Text('SettingPage'),
)
);
}
}
main.dart
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-22-at-00.18.35-1024x623.png)
routes: {
'/' : (context) => HomePage(),
'/profile' : (context) => ProfilePage(),
'/setting' : (context) => SettingPage(),
},
menu.dart
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-21-at-23.56.11.png)
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-21-at-23.57.00-632x1024.png)
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-21-at-23.59.03-1024x172.png)
onTap: () {
Navigator.of(context, rootNavigator: true).pushNamedAndRemoveUntil('/', (route) => false);
},
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-22-at-00.00.13-1024x274.png)
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-21-at-23.57.48.png)
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-21-at-23.58.00.png)
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-22-at-00.14.02-1024x540.png)
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: () {
Navigator.of(context, rootNavigator: true).pushNamedAndRemoveUntil('/', (route) => false);
},
),
ListTile(
leading: Icon(Icons.account_circle),
title: Text('Profile'),
onTap: () {
Navigator.of(context, rootNavigator: true).pushNamedAndRemoveUntil('/profile', (route) => false);
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap: () {
Navigator.of(context, rootNavigator: true).pushNamedAndRemoveUntil('/setting', (route) => false);
},
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-22-at-00.22.57.png)
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-22-at-00.25.52-1024x599.png)
...
selected: ModalRoute.of(context)!.settings.name == '/' ? true : false ,
...
selected: ModalRoute.of(context)!.settings.name == '/profile' ? true : false ,
...
selected: ModalRoute.of(context)!.settings.name == '/setting' ? true : false ,
![](https://thana.in.th/wp-content/uploads/2021/06/Screen-Shot-2564-06-22-at-00.28.07.png)
(Visited 233 times, 1 visits today)