Reputation: 155
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
choiceAction(BuildContext context)async{
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.setBool("isLogin", false);
Navigator.pushNamed(context, '/login');
}
Widget aapBarSection(String title, Color color, BuildContext context){
return AppBar(
title: Text(title, style:TextStyle(fontFamily: 'Poppins-Regular'), ),
centerTitle: true,
backgroundColor: color,
actions: [
PopupMenuButton<String>(
onSelected: choiceAction,
offset: Offset.zero,
itemBuilder: (BuildContext context) {
return <PopupMenuEntry<String>>[
PopupMenuItem(
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(Icons.logout, color: Colors.black,),
),
Text('Logout'),
],
),
value: 'Logout',
)
];
},
)
],
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: (){
exit(0);
},
),
);
}
Want to call the async function inside onSelected property, how do I do that? Because I want to add a logout option in the app bar and On click of logout by calling a function it should change the is_login status in shared preference, and navigate to login screen.
Anybody please help!
Upvotes: 0
Views: 632