_TypeError(类型 'List<SupportTicket>' 不是类型 'List<SupportTicket>' 的子类型

_TypeError (type 'List<SupportTicket>' is not a subtype of type 'List<SupportTicket>'

_TypeError(类型 'List' 不是类型 'List' 的子类型,其中 SupportTicket 来自包:shopping_app_ui/OdooApiCall_DataMapping//SupportTicket.dart
SupportTicket 来自包:shopping_app_ui/OdooApiCall_DataMapping/SupportTicket.dart )

大家好,如果你们确实需要我遗漏的额外信息,请告诉我。

目前,我与未来的建设者有这个问题, 我正在尝试在脚手架中调用未来构建器的未来功能。然后我将使用列表视图生成器。

但是我有一个我无法解决的问题,根据错误,它似乎表明我重复了一些东西?

这是我的 SupportTicket class 代码,其中涉及 json 反序列化。

         class SupportTicket {
           final String ticket_number;
           final String ticket_id;
           final String assigned_user;
           final String check_in;
           final String check_out;
           final String check_in_address;
           final String check_out_address;
           final String subject;
           final String created_date;
           final String rating;
           final String customer_name;
           final String equipment_location;
           
           const SupportTicket({
           
             required this.ticket_number,required this.ticket_id,required this.assigned_user, 
             required this.check_in,required this.check_out,required this.check_in_address, required this.check_out_address,
             required this.subject, required this.created_date, required this.rating, required this.customer_name,
             required this.equipment_location,
           });
           static SupportTicket fromJson(Map<String, dynamic> json) => SupportTicket(
             // if it returns false, because idontknow, odoo return false for null in JSON, 
             //then set it as ' ', otherwise, set it as its normal value, which is usually String  
             ticket_number : json['ticket_number'] == false ? json['ticket_number'] = '' : json['ticket_number'].toString(), 
             ticket_id : json['id'].toString(),
             assigned_user: json['user_id'] == false ? json['user_id'] = '' : json['user_id'][1].toString(),
             check_in: json['check_in'].toString(),
             check_out: json['check_out'].toString(),
             check_in_address: json['check_in_address'].toString(),
             check_out_address: json['check_out_address'].toString(),
             created_date: json['created_date'] == false ? json['created_date'] = '' : json['created_date'].toString(),
             subject: json['subject'] == false ? json['subject'] = '' : json['subject'].toString(),
             rating: json['rating'] == null ? json['rating'] = '0' : json['rating'].toString(),
             customer_name: json['customer_name'] == null ? json['customer_name'] = 'Not Defined' : json['customer_name'].toString(), 
             equipment_location: json['equipment_location'] == null ? json['equipment_location'] = 'Not Defined' : json['equipment_location'].toString(),
           );
         }

这是我的 API 调用 class,它有未来的静态调用,请注意我在这里使用 odoo RPC,如果有人想知道它是一个 xml-rpc JSON 调用了数据。

         import 'package:flutter/widgets.dart';
         import 'package:odoo_rpc/odoo_rpc.dart';
         import 'package:shopping_app_ui/OdooApiCall_DataMapping/ResPartner.dart';
         import '../OdooApiCall_DataMapping//SupportTicket.dart';
         import '../screens/authentication/LoginScreen.dart';
         
           
         //might need to import session id here, to get user id, to get to filter.
         class AllTicketsApi {
         
             static Future <List<SupportTicket>> getAllSupportTickets() async{
             var fetchTicketData = await globalClient.callKw({ //might need to be changed to widget.client.callkw later because of passing user id session.
               'model': 'website.supportzayd.ticket',
               'method': 'search_read',
               'args': [],
               'kwargs': {
                 'context': {}, //because by default odoo fields.char return False when its null, therefore we change the default return '' rather than false
                 'domain': [['state.name','!=','Staff Closed']],
                 'fields':[],
               },
             });
             List listTicket = [];
             listTicket = fetchTicketData; //fetchticketdata(var dynamic) is assigned to List, 
             print ('Get All Support Ticket: '+ fetchTicketData.toString());
             return listTicket.map((json) => SupportTicket.fromJson(json)).toList();
             //listTicket =  fetchTicketData.map((json) => SupportTicket.fromJson(json)).toList(); //convert our json data from odoo to list.    
           }
         
             static Future<int> countOpenSupportTickets(OdooClient client) async {
             var fetchTicketData = await client.callKw({ //might need to be changed to widget.client.callkw later because of passing user id session.
               'model': 'website.supportzayd.ticket',
               'method': 'search_read',
               'args': [],
               'kwargs': {
                 'context': {}, //because by default odoo fields.char return False when its null, therefore we change the default return '' rather than false
                 'domain': [['state.name','=','Staff Closed']],
                 'fields': [
                   'ticket_number',
                   'state'
                 ],
               },
             });
             List listTicket = [];
             listTicket = fetchTicketData; //fetchticketdata(var dynamic) is assigned to List, 
             
             //listTicket =  fetchTicketData.map((json) => ClosedClosedSupportTicket.fromJson(json)).toList(); //convert our json data from odoo to list.
             return listTicket.map((json) => SupportTicket.fromJson(json)).toList().length;
         
           }
         
             static Future <List<ResPartner>> getPartnerImage(String supporticketID) async{
             var fetchTicketData = await globalClient.callKw({
               'model': 'res.partner',
               'method': 'search_read',
               'args': [],
               'kwargs': {
                 'context': {'bin_size': true},
                 'domain': [['id','=',supporticketID as int]],
                 'fields': ['id', 'name', 'email', '__last_update', 'image_128'],
         
               },
             });
         
             List listTicket = [];
             listTicket = fetchTicketData; //fetchticketdata(var dynamic) is assigned to List, 
             print (fetchTicketData.toString());
             //listTicket =  fetchTicketData.map((json) => SupportTicket.fromJson(json)).toList(); //convert our json data from odoo to list.    
             return listTicket.map((json) => ResPartner.fromJson(json)).toList();
           }
         
           /*
           static Future<dynamic> combined() async {
             List  supportticketID = await getAllSupportTickets();
             
             FutureBuilder(
               future: AllTicketsApi.getAllSupportTickets(),
               builder: (context, snapshot) {
                 final tickets = snapshot.data;
                 snapshot.data.value('ticket_id');
                 getPartnerImage(snapshot.data.value('ticket_id'));
                 return
               
               }
             );    
           }
           */
         }

下面是我用于 listviewbuilder 的 buildsupporttickets 小部件。

      Widget buildSupportTickets(List<SupportTicket> supporttickets) =>

        ListView.builder(
          physics: BouncingScrollPhysics(),
          itemCount: supporttickets.length,
          controller: scrollcontroller,
          itemBuilder: (context, index){
        var supportticket = supporttickets[index];

        print('is the problem here before getpartnerimage?');

        var respartnerlist = AllTicketsApi.getPartnerImage(supportticket.customer_id); //fetch partner image data based on support ticket ID.
        
        print (respartnerlist.toString());
        //create a futurebuilder here for respartner, so we will have kind of a nested future builder. i dont know what makes sense anymore, but let us try.

        final avatarUrl ='${globalClient.baseURL}/web/image?model=res.partner&field=image_128&id=${supportticket.customer_id}&unique=${respartnerlist}';
        
        return Padding(
        padding: EdgeInsets.symmetric(
          horizontal: getProportionateScreenWidth(16),
          vertical: getProportionateScreenWidth(4),
        ),
        child: Card(
          elevation: 6,
          color: isDarkMode(context) ? darkGreyColor : Colors.white,
          shadowColor: Colors.grey.withOpacity(0.15),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          child: Padding(
            padding: EdgeInsets.all(getProportionateScreenWidth(8)),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        /*Image.asset(
                          '$productImagesPath/${product.productImage}',
                          height: getProportionateScreenWidth(80),
                          width: getProportionateScreenWidth(80),
                        ),*/
                        SizedBox(width: getProportionateScreenWidth(10)),
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                Container(
                                  width: SizeConfig.screenWidth / 2,
                                  child: Text(
                                    'testingproductname',
                                    overflow: TextOverflow.ellipsis,
                                    maxLines: 1,
                                    style: Theme.of(context).textTheme.subtitle2,
                                  ),
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    Text(
                                      /*'$' +
                                          (product.originalPrice -
                                                  (product.originalPrice *
                                                      product.discountPercent /
                                                      100))
                                              .toStringAsFixed(2),
                                      */
                                      'yo',
                                      style: Theme.of(context).textTheme.subtitle1.copyWith(
                                          fontWeight: Theme.of(context).textTheme.subtitle2.fontWeight),
                                    ),
                                    SizedBox(
                                      width: 10,
                                    ),
                                    Text(
                                      '$',
                                          
                                      style: Theme.of(context)
                                          .textTheme
                                          .caption
                                          .copyWith(
                                            decoration:
                                                TextDecoration.lineThrough,
                                          ),
                                    ),
                                    SizedBox(
                                      width: 10,
                                    ),
                                    Text(
                                      '% off',
                                      style: homeScreensClickableLabelStyle,
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ],
                        )
                      ],
                    ),
                    InkWell(
                      child: Container(
                        padding: EdgeInsets.all(6),
                        decoration: BoxDecoration(
                          color: primaryColor.withOpacity(0.1),
                          borderRadius: BorderRadius.circular(20),
                        ),
                        child: Icon(
                          Icons.delete,
                          size: 22,
                          color: primaryColor,
                        ),
                      ),
                      onTap: () {
                        /*
                        setState(
                          () {
                            myTicketProducts.remove(product);
                          },
                        );
                        */
                      },
                    ),
                  ],
                ),
                Divider(),
                Align(
                  alignment: Alignment.centerRight,
                  child: Padding(
                    padding: EdgeInsets.symmetric(
                      vertical: getProportionateScreenWidth(4),
                    ),
                    child: RichText(
                      text: TextSpan(
                        children: [
                          /*
                          TextSpan(
                            text: product.isAddedInCart
                                ? 'Added in cart'
                                : addToCartLabel,
                            style: product.isAddedInCart
                                ? Theme.of(context).textTheme.caption
                                : homeScreensClickableLabelStyle,
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                setState(
                                  () {
                                    if (!product.isAddedInCart) {
                                      addProductToCart(product, true);
                                    }
                                  },
                                );
                              },
                          ),
                          */
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
          //),
          );
          } 


        );

恕我直言,如果我需要添加任何其他内容供大家参考,请告诉我。

您在 AllTicketsApi class 中遇到了错误。

更改导入 来自

import '../OdooApiCall_DataMapping//SupportTicket.dart';

要//将双斜杠(//)替换为单斜杠(/)

import '../OdooApiCall_DataMapping/SupportTicket.dart';