gpt4 book ai didi

flutter - NoSuchMethodError:在null上调用了 setter/getter 'languageCode'.Receiver:null尝试调用:languageCode

转载 作者:行者123 更新时间:2023-12-03 03:05:06 24 4
gpt4 key购买 nike

单击单选按钮后,我构建了一个用于更改语言的应用程序,但是当更改语言的页面打开时,它显示红色屏幕错误,并显示以下标题。

该错误是:-NoSuchMethodError:在null上调用了getter'languageCode'.Receiver:null尝试调用:languageCode

这里是我的代码:- [如果您需要更多代码,请通知我]

   SettingsPage extends StatefulWidget {   final data;   final method;

SettingsPage({this.data,this.method});

@override _SettingsPageState createState() =>
_SettingsPageState(data: this.data,method: method);

}

class _SettingsPageState extends State<SettingsPage> { var data; int method;

PrayerMethods selectedMethod = PrayerMethods.Umm_Al_Qura_University_Makkah; Languages radioLang;


_SettingsPageState({this.data,this.method}){
if(method!=null){
selectedMethod = PrayerMethods.values[method];
print("starting setting page: selectdMethod: [$method]: [${selectedMethod.toString()}]");
} }

@override void initState() {
print("initState: data.savedLocale.languageCode: ${data.savedLocale.languageCode}");
if(data.savedLocale.languageCode == "ar"){
radioLang = Languages.ar;
}else{
radioLang = Languages.en;
}
print("initState: radioLand: $radioLang");
super.initState(); }



@override Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: new Text(AppLocalizations.of(context).tr("Settings")),
backgroundColor: Color(0xFF614729),
elevation: 10,
),
body: Container(
child: ListView(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.all(15.0),
child: Text(AppLocalizations.of(context).tr("Language"),
style: TextStyle(fontSize: 21,fontWeight: FontWeight.bold),),
),
Column(
children: <Widget>[
RadioListTile(
value: Languages.en,
groupValue: radioLang,
activeColor: Colors.black,
onChanged: (val){
setState(() {
radioLang = val;
});
},
title: Text("English",),),
RadioListTile(
value: Languages.ar,
groupValue: radioLang,
activeColor: Colors.black,
onChanged: (val){
setState(() {
radioLang = val;
});
},
title: Text(AppLocalizations.of(context).tr("Arabic"),
),),
],
),
Divider(
height: 50,
color: Colors.brown,
),
Container(
padding: EdgeInsets.all(15.0),
child: Text(AppLocalizations.of(context).tr("Prayer Methods"),
style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),
),
Column(
children: <Widget>[
RadioListTile(value: PrayerMethods.Umm_Al_Qura_University_Makkah, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Umm Al-Qura University, Makkah", )),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Muslim_WorldLeague, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Muslim World League"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Gulf_Region, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Gulf Region"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Kuwait, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Kuwait"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Qatar, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Qatar"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.University_of_Islamic_Sciences_Karachi, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("University of Islamic Sciences, Karachi",)),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Islamic_Society_of_North_America, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Islamic Society of North America"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Egyptian_GeneralAuthority_of_Survey, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Egyptian General Authority of Survey"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Shia_Ithna_Ansari, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Ithna-Ashari"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.Institute_ofGeophysics_University_of_Tehran, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Institute of Geophysics, University of Tehran"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.MajlisUgama_Islam_Singapura_Singapore, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Majlis Ugama Islam Singapura, Singapore"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.UnionOrganization_islamic_de_France, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Union Organization islamic de France"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.DiyanetIsleri_Baskanligi_Turkey, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Diyanet İşleri Başkanlığı, Turkey"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
RadioListTile(value: PrayerMethods.SpiritualAdministration_of_Muslims_of_Russia, groupValue: selectedMethod,
activeColor: Colors.black,
title: Text(AppLocalizations.of(context).tr("Spiritual Administration of Muslims of Russia"),
),
onChanged: (val){
setState(() {
selectedMethod = val;
});
}),
],
),
],
),
],

),
),

floatingActionButton: Container(
width: 100.0,
height: 50.0,
child: FloatingActionButton(onPressed: () async{
_onLoading();
if(selectedMethod.index != method){
await updateLanguageAndMethod();
}
Navigator.pop(context);
changeLanguage(data,radioLang.index);
Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) => MainScreen()));
},
child: new Text(AppLocalizations.of(context).tr("Save"),style: TextStyle(fontSize: 15.0),),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
elevation: 10,
backgroundColor: Color(0xFF614729),
),
),
); } void changeLanguage(var data,int value){
this.setState(() {
switch (value) {
case 0:
updateLanguageInSharedPrefs(value);
data.changeLocale(Locale("en"));
print("changeLanguage(): EN selected");
break;
case 1:
updateLanguageInSharedPrefs(value);
data.changeLocale(Locale("ar"));
print("changeLanguage(): AR selected");
break;
}
}); } void updateLanguageInSharedPrefs(int lang) async{
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('language', lang); }

dynamic getLanguageInSharedPrefs() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.get('language'); }

Future<String> updateMethodInSharedPrefs(int method) async{
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt('prayer_method', method);
String value = "updateMethod: $method";
print(value);
return value;

}

void updateLanguageAndMethod() async{
await updateMethodInSharedPrefs(selectedMethod.index);
MonthlyPrayerData monthlyPrayerData = await updatePrayerDataFileUsingAPI(method: selectedMethod.index);
print("updateLanguageAndMethod completed.");

}

void _onLoading() {
showDialog(
builder: (_) => Center(child: CircularProgressIndicator()),
context: context,
barrierDismissible: false,
); }

}

最佳答案

从错误中我们可以说data.savedLocale为null。我们无法提供所提供的大量信息。

也许提供更多的代码。

关于flutter - NoSuchMethodError:在null上调用了 setter/getter 'languageCode'.Receiver:null尝试调用:languageCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57697382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com