i am using shared preference to pass data from one screen to other, it was working perfectly few days ago, but now it is sending this error
Invalid argument(s) (value): Must not be null
i'm calling login api, it is running sucessfully, i am getting api data on its response but it goes to catch part after print the data, it is not navigating to other screen, here is the login function code
SharedPreferences myPrefs;
Future login() async {
Dio dio = new Dio();
try {
data = {
'username':"Munib khatri",
'password':"Munib123",
'date': formattedDate
};
await dio
.post(localhostUrlLogin, data: json.encode(data),)
.then((onResponse) async {
print(onResponse.data);
String name = (onResponse.data['User']['username']);
String email = (onResponse.data['User']['email']);
String designation = (onResponse.data['User']['Designation']);
String token = (onResponse.data['AccessToken']);
//here i am calling another api
data={
"token":token,
"username":name,
"leave":"Approved",
"type":"maternity"
};
dio
.post(localHostUrlleaveCount, data: json.encode(data))
.then((onResponse) async {
int sickCount=(onResponse.data['sick']);
int annualCount=(onResponse.data['annual']);
await myPrefs.setInt('sickCount', sickCount);
await myPrefs.setInt('annualCount', annualCount);
}).catchError((onerror){
});
await myPrefs.setString('name', name);
await myPrefs.setString('email', email);
await myPrefs.setString('designation', designation);
Navigator.push(
context, new MaterialPageRoute(builder: (context) => Navigation()));
});
} catch (e) {
print(e.toString());
}
}
Navigation:
class Navigation extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
theme: new ThemeData(primaryColor: Colors.blue),
home: EmployeeNavigation(),
);
}
}
int _selectedTab = 0;
final _pageOptions = [Home(), location(), Profile()];
String getname = "";
String getemail = "";
String getdesignation = "";
String getaccesstoken = "";
// ignore: must_be_immutable
class EmployeeNavigation extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return EmployeeNavigationState();
}
}
class EmployeeNavigationState extends State<EmployeeNavigation> {
var email;
var designation;
var date;
bool valuefirst = false;
String backtext = "";
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (_selectedTab == 0) {
return true;
}
setState(() {
_selectedTab = 0;
});
return false;
},
child: Scaffold(
drawer: NavigationDrawerWidget(), //this is a drawer file
body: _pageOptions[_selectedTab],
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.blue[50],
type: BottomNavigationBarType.fixed,
currentIndex: _selectedTab,
onTap: (value) {
print(value);
setState(() {
_selectedTab = value;
});
},
items: [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
BottomNavigationBarItem(
icon: Icon(Icons.location_on), label: "Location"),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: "Profile",
),
],
)));
}
}
i am getting response of both api, but can't navigate to other screen.