用户对问题“只有导航器在Inkwell的onTap()内部工作”的回答

您所在的位置:网站首页 sharedpreferences翻译 用户对问题“只有导航器在Inkwell的onTap()内部工作”的回答

用户对问题“只有导航器在Inkwell的onTap()内部工作”的回答

2023-06-07 12:35| 来源: 网络整理| 查看: 265

我正在列出通知。当用户单击通知时,我希望更新数据库中的读状态。我在Inkwell小部件的OnTap()函数中使用了update函数,还使用了下一页的导航。但是异步函数没有调用。有没有可能解决这个问题?

这是我的密码:

class NotificationList extends StatefulWidget { const NotificationList({Key? key}) : super(key: key); @override _NotificationListState createState() => _NotificationListState(); } class _NotificationListState extends State { String useremail = ''; String appusertype = ''; Future getList() async { SharedPreferences preferences = await SharedPreferences.getInstance(); setState(() { useremail = preferences.getString('useremail') ?? "Not found"; //debugPrint(useremail); // debugPrint(appusertype); }); Map headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Charset': 'utf-8' }; Map body = { "email": useremail, }; var bodyEncoded = body.keys.map((key) => "$key=${body[key]}").join("&"); //print(bodyEncoded); var url = "/notification_list.php"; var response = await http.post(Uri.parse(ApiConstant.baseUrl + url), headers: headers, encoding: Encoding.getByName('utf-8'), body: bodyEncoded); return json.decode(response.body); } Future updateStatus(id) async { Map headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Charset': 'utf-8' }; Map body = { "id": id, }; var bodyEncoded = body.keys.map((key) => "$key=${body[key]}").join("&"); //print(bodyEncoded); var url = "/update_notification.php"; var response = await http.post(Uri.parse(ApiConstant.baseUrl + url), headers: headers, encoding: Encoding.getByName('utf-8'), body: bodyEncoded); print(id); print("object"); return jsonDecode(response.body); } @override void initState() { super.initState(); // checkLogin(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: const Color.fromARGB(255, 30, 64, 122), title: const Text( 'Notifications', style: TextStyle(color: Colors.orange), ), centerTitle: true, bottom: const PreferredSize( preferredSize: Size.zero, child: Text( "عرض قائمة الممتلكات", style: TextStyle(color: Colors.orange), )), ), body: Container( decoration: const BoxDecoration( image: DecorationImage( image: AssetImage("assets/building.jpg"), fit: BoxFit.cover, )), child: Padding( padding: const EdgeInsets.all(8.0), child: FutureBuilder( future: getList(), builder: ((context, AsyncSnapshot snapshot) { if (snapshot.hasError) print(snapshot.error); //print("object"); if (snapshot.hasData) { List list = snapshot.data as List; if (list.isEmpty) { return const Center( child: Card( color: Colors.white, child: Padding( padding: EdgeInsets.all(20.0), child: Text('No Notifications yet!'), ))); } return ListView.builder( itemCount: snapshot.data!.length, itemBuilder: ((context, index) { List? list = snapshot.data as List?; return InkWell( onTap: () async { updateStatus(list![index]['id']); print(list[index]['id']); list[index]['title'] == "Interest Request" ? Navigator.push( context, MaterialPageRoute( builder: (context) => const InterestRequestList())) : null; }, child: Card( color: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10)), child: Padding( padding: const EdgeInsets.all(20.0), child: Row( children: [ // Container( // width: 50, // height: 70, // decoration: const BoxDecoration( // image: DecorationImage( // image: AssetImage ("assets/building.jpg"), // fit:BoxFit.cover, // ) // ),), const Expanded( flex: 1, child: Icon( Icons.notifications, color: Colors.grey, ), ), //Spacer(), Expanded( flex: 5, child: Padding( padding: const EdgeInsets.fromLTRB( 10, 0, 0, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ list![index]['read_status'] == '0' ? Text( list[index]['title'], style: const TextStyle( color: Colors.orange, fontSize: 15), ) : Text( list[index]['title'], style: const TextStyle( color: Colors.orange, fontSize: 15), ), Text(list[index]['body']), ]), ), ), //const Spacer(), const Expanded( flex: 1, child: Icon(Icons.arrow_forward_ios)), ], ), ), ), ); })); } return const Center( child: Card( color: Colors.white, child: Padding( padding: EdgeInsets.all(20.0), child: Text('No Notifications yet!'), ))); // else { // return const Center( // child: CircularProgressIndicator(), // ); // } }), )), )); } }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3