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

Time:06-01

_TypeError (type 'List' is not a subtype of type 'List' where SupportTicket is from package:shopping_app_ui/OdooApiCall_DataMapping//SupportTicket.dart
SupportTicket is from package:shopping_app_ui/OdooApiCall_DataMapping/SupportTicket.dart )

Hi guys, tell me if you guys do need extra information that I have missed.

currently, I have this problem with a future builder, I'm trying to call my future function of future builder inside a scaffold. I will then use a listview builder.

However i am having a problem that I just cannot solve, based on the errors,it seems to indicate that I have duplicated something?

This is my code for SupportTicket class which involved json deserialization.

         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(),
           );
         }

This is my API call class which have the future static call, note that i am using odoo RPC here, if anyone is wondering it is an xml-rpc with JSON data called.

         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
               
               }
             );    
           }
           */
         }

Below is my buildsupporttickets widget used for listviewbuilder.

      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);
                                    }
                                  },
                                );
                              },
                          ),
                          */
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
          //),
          );
          } 


        );

With all due respect please tell me if i need to add anything else for you guys reference.

CodePudding user response:

you got the error in the AllTicketsApi class.

change your import From

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

To //Replace the double slash(//) with single slash (/)

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