发布应用程序时导航不起作用

Navigation not working when release app flutter

我想从登录屏幕导航到主屏幕,进入我的 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,
        ),
      )
      );
    }

我要导航到主页的 login/signup 页面:

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.');
      }
    }

有什么帮助吗?

enter image description here

  1. 您是否在您的应用中授予了互联网权限?