发布应用程序颤动时导航不起作用
Posted
技术标签:
【中文标题】发布应用程序颤动时导航不起作用【英文标题】:Navigation not working when release app flutter 【发布时间】:2021-02-18 22:22:23 【问题描述】:我想从登录屏幕导航到主屏幕进入我的 Flutter 应用程序。我的应用在模拟器或虚拟设备上测试时运行良好,但在创建构建版本 apk 时,导航到主页不起作用。在注册或登录页面上,导航不起作用。 我的主要文件是:
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,
'Error!',
'Failed to Register.Please try again.Thanks!');
throw Exception('Failed to login.');
有什么帮助吗?
【问题讨论】:
尝试在屏幕更改时以配置文件模式运行它并使用日志 您是否在清单中声明了 Internet 权限? 不,我没有添加,这些互联网权限是否与导航相关联?? 【参考方案1】:enter image description here
-
您是否在您的应用中授予了互联网权限?
【讨论】:
以上是关于发布应用程序颤动时导航不起作用的主要内容,如果未能解决你的问题,请参考以下文章