TypeError:null不是对象(评估'_reactNativeDefaultPreference.default.get')

时间:2020-09-10 05:18:14

标签: react-native

首次登录时,业务ID将为null,然后在WebViewPage调用后,我将值存储在业务ID和资源ID中。最初它没有任何价值,我对如何处理这种情况感到困惑。我想在DefaultPreference存储后从它检索业务ID和资源ID,但是我遇到了以上错误。任何帮助将不胜感激。谢谢。

import React from 'react';
import {View,ImageBackground, Image, Platform} from 'react-native';

import NetInfo from "@react-native-community/netinfo"
import DefaultPreference from 'react-native-default-preference';

export default class SplashScreen extends React.Component {
    constructor(props) {
      super(props);
      var SharedPreferences = require('react-native-shared-preferences');
      if (Platform.OS === 'android') {
      SharedPreferences.getItems(["business_entity_id","resorce_id","userid"],(values) => {
        console.log("after");
        const business_entity_id = values[0]
        if (business_entity_id === null)
        {
            business_entity_id = ""
        }
        const resorce_id = values[1]
        if (resorce_id === null)
        {
            resorce_id = ""
        }
        console.log(business_entity_id);
    
        setTimeout(() => {
         
            load();
       
      }, 2000);
    
      load = () => {
       
        let internetconnection = NetInfo.addEventListener(state => {
    
            if (state.isConnected === true) 
            {
                console.log(business_entity_id);
                if (business_entity_id == ""  && resorce_id == "") {
                    
                    props.navigation.navigate('PracticeCode');
                   
                }
                else if(resorce_id == "")
                {
                    props.navigation.navigate('DoctorDetails');
                }
                else {
                    console.log("next")
                    props.navigation.navigate('Calendar');
                }
            }
            else {
                Alert.alert("Alert",
                    "Please check your Internet Connection");
            }
        });
    };
    });
       
}
else{

    setTimeout(() => {   
        load();
      }, 2000);

  load = () => {
   
    let internetconnection = NetInfo.addEventListener(state => {

        if (state.isConnected === true) 
        {
            DefaultPreference.get('business_entity_id').then(function(value) {console.log(value)});
            DefaultPreference.get('userid').then(function(value) {console.log("userid",value)});

             props.navigation.navigate('PracticeCode');
               
        }
        else {
            Alert.alert("Alert",
                "Please check your Internet Connection");
        }
    });
};

}
    }
    render() {
        return (
        <View style={ {
            width: '100%'
          }}>
    <View>
    <ImageBackground source={require('./../assets/bg.jpg')} style={ {
        resizeMode: "cover",
        justifyContent: "center",
        alignItems: 'center',
        width: '100%',
        height: '100%'
    }}>
        <View style={{
        position: "absolute",
        left: 0,
        width: '100%',
        height: '100%',
        backgroundColor: '#fff',
        opacity: 0.9
    }}></View>
        <Image style={ {
        width: 250,
        resizeMode: 'cover'
    }} source={require('./../assets/splash.png')} />
    </ImageBackground>
    </View>
   
</View>
        );
    }
}

0 个答案:

没有答案