type _Uint8ArrayView' is not a subtype of type 'String' in Flutter

1,370

I am working in a similar problem, but trying to fetch GIS geography types from postgres.

In your case, if you are really really sure it is a String you can use utf8.decode(uint8List). In the constructor, see example:

    IoTDevice(index, mac, imei, backend, ByteData lastpos, status, lockstatus, 
    powerstatus, id, chargestatus, Uint8List lastping){
    this.index = index;
    this.mac = '';
    for (final byte in mac){
      this.mac += byte.toRadixString(16);
    /// In your case, you should use: this.mac = utf8.decode(mac)
    }
    print('mac ${this.mac}');
    this.imei = imei;
    this.backend = backend;
    if(lastpos != null){
      var longitude = lastpos.getFloat64(0);//Still errors here, trying to solve
      var latitude = lastpos.getFloat64(8); //Still errors here, trying to solve
      print('Longitude: ${longitude}');
      print('Latitude: ${latitude}');
      this.lastpos = LatLng(longitude, latitude);
    }
    else {
      this.lastpos = null;
    }
    print('lastpos ${this.lastpos}');
    this.status = status;
    this.lockstatus = lockstatus;
    this.powerstatus = powerstatus;
    this.id = id;
    this.chargestatus = chargestatus;
    lastping != null ? this.lastping = DateTime.tryParse(new String.fromCharCodes(lastping).trim()) : this.lastping = null;
    print('lastping ${this.lastping}');
  }

  static IoTDevice fromDynamicMap(Map<String, dynamic> map) => IoTDevice(
      map['index'],
      map['mac'],
      map['imei'],
      map['backend'],
      map['lastpos'],
      map['status'],
      map['lockstatus'],
      map['powerstatus'],
      map['id'],
      map['chargestatus'],
      map['lastping']
    );

If it's not a String it will launch an Offset error.

Then you have to go with ByteData and pray all the gods available. I am on this point right now, if I get any enlightment I will let you know.

EDIT: Additional information on how the Uint8Arrayviews come in here Unreadable Int16 from UInt8List, wrong data when cast asByteArray

I hope between both comments you can fix it

Share:
1,370
Paresh Mangukiya
Author by

Paresh Mangukiya

I am a Mobile App Developer and Team Leader at BlueBit Technologies, in this My core competency lies in the complete end-to-end management and completing the entire project (iOS, Android and Backend side). I am seeking opportunities to build Mobile Apps from the ground up for you or your business. Please feel free to contact me here ⬇ Skype: pkmangukiya_1 Mobile or WhatsApp: +91 9723680658 Email: [email protected] I have spent 4+ years in the IT industry, I have developed a wide range of (iOS and Android) Applications using iOS (Swift, Objective-C), Flutter(Dart) and Android (Kotlin, Java). I work with B2B clients - Software companies and as well as B2C - Small and Medium Enterprises (SME) in many vertical industries and I passionate about good service &amp; deliver a high-quality product. I have experience in mobile Application Development, App principles, processes, theories and concepts. I am involved in the full life cycle of designing, developing, testing, Analysis, and maintaining applications. And I have also enough knowledge and experience of how to use and where to use Encryption, Exception Handling, Token-based Authentication and other security features in applications. My core competency lies in complete end-to-end management of new Mobile Applications and I am seeking opportunities to build Mobile Apps from the ground up for you or your business. My experience has been awesome and good so far, I have learned a lot of new things and worked during this time. My years of experience have prepared me well for this position. Skills: Programming Languages: iOS: Swift and Objective C Flutter: Dart Android: Java and Kotlin C/C++ Professional Experience: Socket Programming DB &amp; API Design Google API, Facebook API, Google Maps and Direction, Location Services Integrating ads ( Google Ads, Admob, Facebook Ads), Media Player Functionalities API security with JWT JSON, XML In-app purchase User Authentication Chat and Messaging Hosting (App Store, Play Store) Payment Gateways Social Media Integration SQLite Database, Firebase Database, MySQL Database Advanced Analytics Mobile Application Design Document Conversion Projects Variations: Chatting and Messaging: Text and Voice messaging, video communication, photo &amp; video sharing Loan Management System Online Music Streaming QR &amp; Barcode Scanner Parking Facility Social Media: Professional networks, social networks and Data Sharing Lifestyle: Religion, travel, blogs, fashion, health, fitness Music + Audio Video Mixer with dynamic features Football Training Club and Academy Photo and Video Editor App Organization Management Society management Quiz - Play &amp; Win I really enjoy programming a lot!

Updated on December 26, 2022

Comments

  • Paresh Mangukiya
    Paresh Mangukiya 11 months

    I fetch the data from the SQLite database in my app and show that data as a list, but when I get the value and I trying to manipulate data, I am getting this error

    I am getting this error.

    type '_Uint8ArrayView' is not a subtype of type 'String'
    

    I show data on this

    FutureBuilder<List<QuestionModel>>(
      future: DatabaseHelper.instance.getQuestionList(),
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        if (snapshot.hasData) {
          return ListView.builder(
            itemCount: snapshot.data.length,
            itemBuilder: (BuildContext context, int index) {
              QuestionModel item = snapshot.data[index];
              return ListTile(
                title: Text(item.questionen),
                leading: Text(item.id.toString()),
    
              );
            },
          );
        }
        else if(snapshot.hasError){
          print('Error-------> ${snapshot.error}');
          return Text('Error: ${snapshot.error}');
        }
        else {
          return Center(child: CircularProgressIndicator());
        }
      },
    )
    

    This is my model class

    class QuestionModel {
      int id;
      String questionen;
      String opta;
      String optb;
      String optc;
      int answer;
      String imgpath;
    
      QuestionModel(
          {this.id,
          this.questionen,
          this.opta,
          this.optb,
          this.optc,
          this.answer,
          this.imgpath});
    
      factory QuestionModel.fromMap(Map<String, dynamic> json) => new QuestionModel(
            id: json["id"] ?? "",
            questionen: json["questionen"] ?? "",
            opta: json["opta"] ?? "",
            optb: json["optb"] ?? "",
            optc: json["optc"] ?? "",
            answer: json["answer"] ?? "",
            imgpath: json["imgpath"] ?? "",
          );
    }
    

    This is the function of fetch data from the database

    Future<List<QuestionModel>> getQuestionList() async {
    
      final db =  await database;
      var res = await db.query("question_data");
    
      print(res.toString());
      List<QuestionModel> queList =
      res.isNotEmpty ? res.map((c) => QuestionModel.fromMap(c)).toList() : [];
      return queList;
    }