在“无数据”小部件的情况下拉动刷新

问题描述

我需要这方面的帮助,请我有一个 Refreshindicator,它可以在数据库中有数据时加载 ListView,但是如果表为空而不是 ListView,我想让小部件返回 Text 小部件“无数据”。 但是当表为空时会出现错误
_TypeError(“String”类型不是“Iterable”类型的子类型)
这将出现在刷新方法中我不知道我该怎么做我感谢任何帮助提前感谢。 这是页面的 UI

class _onlineResultTab extends State<onlineResultTab> {
 List<ResultsModelClass> resultslist = new List();
 List<CoursesModelClass> coursesist = new List();

 ResultsModelClass resultsModelClass;
 CoursesModelClass courseModelClass;

 final GlobalKey<RefreshindicatorState> refreshKey = GlobalKey<RefreshindicatorState>();
 DataApiProvider dataApiProvider = new DataApiProvider();
 
 Widget build(BuildContext context) {
   return Scaffold(
     body: Refreshindicator(
       key: refreshKey,onRefresh: refreshList,child: _resultwidget(context),),);
 }

 fetchResultDetails() async {
   final allRows = await DbHelper.mydb.getonlineResultList();

   allRows.forEach((row) => {
         resultsModelClass = ResultsModelClass(
             "",row["Res_Stud_Index"],row["Res_Stud_Name"],row["Res_Sem"].toString(),"",row["Res_Batch"],row["Res_Courses"],row["Res_Grade"],row["Res_GPA"].toString(),row["Res_CGPA"],row["Res_Status"],row["faculty_desc_e"],row["major_desc_e"]),resultslist.add(resultsModelClass)
       });
   if (this.mounted) {
     setState(() {});
   }
 }

 fetchCourse() async {
   final allRows = await DbHelper.mydb.getResultcoursesList();

   allRows.forEach((row) => {
         courseModelClass = CoursesModelClass(
           row["Res_Courses"],coursesist.add(courseModelClass)
       });
   if (this.mounted) {
     setState(() {});
   }
 }

 List<String> listHeader = ['Student Results Details'];
 Widget _resultwidget(context) {
   final _size = MediaQuery.of(context).size;
   return resultslist.length == 0
       ? ListView.builder(
           controller: ScrollController(),itemCount: 1,itemBuilder: (context,index) {
             return Center(
                 child: Padding(
               padding: EdgeInsets.only(top: _size.height * 0.4),child: Text(
                 "No Result Details !",style: TextStyle(fontSize: 20),));
           },physics: AlwaysScrollableScrollPhysics(),)
       : new ListView.builder(
           itemCount: listHeader.length,index) {
             //var _size = MediaQuery.of(context).size;
             return SingleChildScrollView(
               child: Center(
                   child: Padding(
                       padding: EdgeInsets.only(bottom: _size.height * 0.02),child: Column(
                         children: [
                           Card(
                             elevation: 20,margin: EdgeInsets.symmetric(
                               horizontal: _size.width * 0.005,child: Container(
                               height: 50.0,decoration: Boxdecoration(
                                   color: Theme.of(context).backgroundColor),child: Center(
                                 child: Text(
                                   'Semester ' +
                                       resultslist[0].Res_Sem +
                                       ' Result  ',style: TextStyle(
                                       color: Colors.white,fontSize: 17,fontWeight: FontWeight.bold),],))),);
               },);
 }

刷新方法

Future<String> refreshList() async {
    refreshKey.currentState?.show(atTop: false);
    //await Future.delayed(Duration(seconds: 10));
    var studentIndex;
    final allRows = await DbHelper.mydb.MainInfoCehck();
    allRows.forEach((row) => {
          row["Stud_Index"],studentIndex = row["Stud_Index"].toString()
          //print( row["Stud_Index"].toString())
        });
    print(studentIndex);

    //void refreshResult(String studentIndex)async{
    await dataApiProvider.refresh_result(studentIndex);

    // }
    if (this.mounted) {
      setState(() {
        coursesist.clear();
        resultslist.clear();
        fetchResultDetails();
        fetchCourse();
      });
    }

    return null;
  }
Future<String> refresh_result(String studentIndex) async {
    var url = main_urll + "?studentIndex=" + studentIndex.trim();

    final response = await http.get(url);

    List<ResultDetailsModel> ResulttDetailsListModel = [];
    final resultInfo = jsonDecode(response.body)['result_info'];

    DbHelper.mydb.deleteTableData("Result");
    print('Result informations : ' + resultInfo.toString());

    for (Map i in resultInfo) {
      ResulttDetailsListModel.add(ResultDetailsModel.fromJson(i));
      DbHelper.mydb.saveResultDetails(ResultDetailsModel.fromJson(i));
    }

    return "";
  }

解决方法

请检查是否

resultslist == null resultslist.isNotEmpty()

用于处理空列表