Flutter AppBar with clickable options for easy navigation in your app.
Flutter Tutorial
Install Flutter in Win/Linux/Mac
Flutter Widgets:
Bottom Navigation Bar in Flutter
Auto Close Keyboard in Flutter
Screen size handling in Flutter
Flutter REST API
Flutter Advance
Wrap vs Builder vs OverBarFlow
Circular progress contain Icon
Flutter State management Comparison
Flutter Database
Flutter Token Expired Handling
Flutter Provider
Flutter GetX
Flutter with Native
Flutter Tips
Interview Questions
Appbar in flutter is very important for every application, in most of the cases we need appbar with clickable option and in this case when user clicks on popup menu it will go to next screen and when on another screen When clicked it returns to the previous screen. You can add your own feature as per your requirement
import 'package:flutter/material.dart';
class AppBarResearchThinkerExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ResearchThinker Home Page'),
actions: [
PopupMenuButton<String>(
onSelected: (value) {
// Handle menu item selection
print('Selected: $value');
},
itemBuilder: (BuildContext context) => [
PopupMenuItem<String>(
value: 'Home',
child: Text('Home'),
),
PopupMenuItem<String>(
value: 'Second Page',
child: InkWell(
onTap: () {
//In this first pop close menu button second push to Navigate to second page
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondPage()),
);
},
child: Text('Second Page')),
),
PopupMenuItem<String>(
value: 'Close',
child: InkWell(
onTap: () {
//This will close menu on appbar
Navigator.pop(context);
},
child: Text('Close')),
),
],
),
],
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Navigate to another Second screen
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondPage()),
);
},
child: Text('Go to Second Page'),
),
),
);
}
}
//This is a second Screen/Page
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ResearchThinker Second Page'),
actions: [
PopupMenuButton<String>(
onSelected: (value) {
// Handle menu item selection
print('Selected: $value');
},
itemBuilder: (BuildContext context) => [
PopupMenuItem<String>(
value: 'Option ',
child: Text('Option'),
),
PopupMenuItem<String>(
value: 'Option B',
child: InkWell(
onTap: () {
//This will close menu on appbar & move to previous screen
Navigator.pop(context);
Navigator.pop(context);
},
child: Text('Previous Page')),
),
PopupMenuItem<String>(
value: 'Close',
child: InkWell(
onTap: () {
//This will close popup menu on Appbar
Navigator.pop(context);
},
child: Text('Close')),
),
],
),
],
),
body: Center(
child: Text('This is the Second Page'),
),
);
}
}
Note : you can change position of popup menu button through Offset value