如何解决释放应用程序时导航不起作用
我想从登录屏幕导航到主屏幕,进入我的flutter应用程序。在模拟器或虚拟设备上测试我的应用程序时,它运行良好,但是在创建构建版本apk时,无法导航到Home。在注册或登录页面上,导航不起作用。 我的主文件是:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
String isLogin = prefs.getString('navigateToHome');
prefs.setString('is_mechanic','1');
Widget _defaultHome = new LoginUI();
// isLogin = 'false';
if (isLogin == 'true') {
//If the user is an loggedin
print('home page');
_defaultHome = new Home();
} else {
// If the user is not loggedin
print('LoginUI page');
_defaultHome = new LoginUI();
}
runApp(MaterialApp(
title: 'Navigation Basics',//navigateToHome
// home: FirstRoute(),//android device
home: _defaultHome,debugShowCheckedModeBanner: false,theme: ThemeData(
primaryColor: Colors.black,),)
);
}
我要从中导航到主页的登录/注册页面:
Future<loginModel> signUpUserOrMechanic(String email,String pass,String cellPhone,String name,String workshop) async {
final prefs = await SharedPreferences.getInstance();
var userOrMechanic = prefs.getString('is_mechanic');
var nick = name.substring(0,2);
var uri = new Uri.http(url,"/API/Signup/get",{
"Email": email,"Password": pass,"PhoneNumber": cellPhone,"ismechanic": userOrMechanic,"Name": name,"WorkshopAddress": workshop,"NickName": nick,"Latitude": '',"Longitude": '',"WorkshopName": '',});
final response = await http.get(uri);
if (response.statusCode == 200) {
final jsonObj = jsonDecode(response.body);
var responseObject = jsonDecode(response.body);
var user = loginModel.fromJson(responseObject);
// print('${user.clientOrMechanic} is ${user.alias}');
// print('${user.clientOrMechanic} is awesome');
prefs.setString('phone_no',cellPhone);
if (user.clientOrMechanic == "Already Registered") {
Utility.getInstance().showAlertDialog(
navigatorKey.currentState.overlay.context,'System Alert!','You are already registered.Thanks!');
} else if (user.clientOrMechanic == "Registration Successful") {
prefs.setString('navigateToHome','true');
navigatorKey.currentState.push(MaterialPageRoute(
builder: (context) => Home(),));
// Get.to(Home());
} else {
Utility.getInstance().showAlertDialog(
navigatorKey.currentState.overlay.context,'Error!','Failed to Register. Please try again or contact to support. Thanks!');
}
return loginModel.fromJson(json.decode(response.body));
} else {
// If the server did not return a 201 CREATED response,// then throw an exception.
Utility.getInstance().showAlertDialog(
navigatorKey.currentState.overlay.context,'Failed to Register.Please try again.Thanks!');
throw Exception('Failed to login.');
}
}
有帮助吗?
解决方法
- 您是否在应用中授予了访问互联网的权限?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。