Flutter 仅从颤振中的完成日期提取年份
这是我的json数据结构:Flutter 仅从颤振中的完成日期提取年份,flutter,dart,Flutter,Dart,这是我的json数据结构: [ [ { "nos": 0, "name": "A S MUSIC AND DANCE A CULTURAL ORGANIZATION", "unique_id": "AN/2020/0259067", "reg_details": [ {
[
[
{
"nos": 0,
"name": "A S MUSIC AND DANCE A CULTURAL ORGANIZATION",
"unique_id": "AN/2020/0259067",
"reg_details": [
{
"registered_with": "Registrar of Societies"
},
{
"type_of_ngo": "Registered Societies (Non-Government)"
},
{
"registration_no": "1534"
},
{
"copy_of_registration_certificate": "Available"
},
{
"copy_of_pan_card": "Available"
},
{
"date_of_registration": "25-05-2016"
}
],
我只想与年份进行比较,仅从日期键开始,即“注册日期”:“25-05-2016”
从窗口小部件获取值的我的按钮是:
RoundedButton(
text: "Next",
press: () async {
debugPrint(_currentValue.toString());
_NgoDetail(ngo,_currentValue.toString());
//Where _currentValue is actually the year I'm getting
//from a spinner widget
},
),
与这些值进行比较的函数是:
Future<bool> _NgoDetail(String name,String year) async { //Only Year as a
// parameter and not whole date
String jsonString = await _loadANgoAsset();
final jsonResponse = json.decode(jsonString);
int k=-2;
List<dynamic> allNamesOfNGO=jsonResponse[0];
allNamesOfNGO.takeWhile((value) => value != name).forEach((allNamesOfNGO){
(allNamesOfNGO as Map<String, dynamic>).forEach((key, value) {
++k;
if(key=='name' && value == name){
if(key=='date_of_registeration' && value == year) //Here value is
//complete date, I want
//it to be year only
{
Navigator.push(context,MaterialPageRoute(builder: (context)=> R3(jsonIndexOfNGO:k)));
}
}
else{
Fluttertoast.showToast(
msg: "Your given details doesn't match. Please try again",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 3,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
} );
});
}
Future\n详细信息(字符串名称,字符串年份)异步{//仅作为
//参数,而不是整个日期
字符串jsonString=await_loadANgoAsset();
最终jsonResponse=json.decode(jsonString);
int k=-2;
列出allNamesOfNGO=jsonResponse[0];
takeWhile((值)=>value!=name).forEach((AllNamesOfGo){
(作为映射的所有名称)。forEach((键,值){
++k;
if(key='name'&&value==name){
if(key='date\'of\'u registration'&&value==year)//这里的值是
//完成日期,我要
//这将是唯一的一年
{
push(context,MaterialPageRoute(builder:(context)=>R3(jsonIndexOfNGO:k));
}
}
否则{
烤面包片(
msg:“您提供的详细信息不匹配。请重试”,
烤面包片长度:烤面包片长度,
地心引力:ToastGravity.CENTER,
时间:3,
背景颜色:Colors.red,
textColor:Colors.white,
体积:16.0),;
}
} );
});
}
在上述函数中,我首先应该做什么?从json中检索所有日期值,并将其格式从此25-02-2015
转换为2015
,或执行其他方法?尝试此方法
List<dynamic> allNamesOfNGO=jsonResponse[0];
allNamesOfNGO.takeWhile((value) => value != name).forEach((allNamesOfNGO){
(allNamesOfNGO as Map<String, dynamic>).forEach((key, value) {
++k;
if(key=='name' && value == name){
if(key=='date_of_registeration' && value.substring(6) == year) //Here value is
//complete date, I want
//it to be year only
{
Navigator.push(context,MaterialPageRoute(builder: (context)=> R3(jsonIndexOfNGO:k)));
}
}
else{
Fluttertoast.showToast(
msg: "Your given details doesn't match. Please try again",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 3,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
}
List allNamesOfNGO=jsonResponse[0];
takeWhile((值)=>value!=name).forEach((AllNamesOfGo){
(作为映射的所有名称)。forEach((键,值){
++k;
if(key='name'&&value==name){
if(key='date\u of\u registration'&&value.substring(6)==year)//这里的值是
//完成日期,我要
//这将是唯一的一年
{
push(context,MaterialPageRoute(builder:(context)=>R3(jsonIndexOfNGO:k));
}
}
否则{
烤面包片(
msg:“您提供的详细信息不匹配。请重试”,
烤面包片长度:烤面包片长度,
地心引力:ToastGravity.CENTER,
时间:3,
背景颜色:Colors.red,
textColor:Colors.white,
体积:16.0),;
}
}
参数已经是年格式。我指的是2015年或2016年等。我想从API中提取和比较值,以便在函数\n详细信息(字符串名称,字符串年份)
中仅为年而不是2015年2月25日。请再次编辑您的答案。谢谢!我编辑了,请检查