Home > Software engineering >  Dart What are the concrete classes which are used to extend or implement the build-in types in dart
Dart What are the concrete classes which are used to extend or implement the build-in types in dart

Time:11-02

I want to use a typed list in dart that can be one of the following types

/// The array  is typed array it can be :
/// - Float64List
/// - Float32List
/// - Int32List
/// - Uint32List
/// - Int16List
/// - Uint16List
/// - Uint8ClampedList
/// - Uint8List
/// - Int8List
///
/// and can be the object positions, colors, normals or uvs or indices
dynamic array;

I will like to have something like this

TypedArray array;

For now I use dynamic but I want to use an abstract class that hass all the properties of the typed lists.

How I can do that thank you all.

An example of what I am trying to do

class BufferAttribute {
  /// The array  is typed array it can be :
  /// - Float64List
  /// - Float32List
  /// - Int32List
  /// - Uint32List
  /// - Int16List
  /// - Uint16List
  /// - Uint8ClampedList
  /// - Uint8List
  /// - Int8List
  ///
  /// and can be the object positions, colors, normals or uvs or indices
  TypedData array;

  /// 1,2 or 3 components per iteration
  int itemSize;
  bool normalized;

  /// the number of elements in the array.
  /// how is computed: array.length / numbe of components.
  int count = 0;

  /// gl.STATIC_DRAW
  int usage = 35044;

  BufferAttribute(this.array, this.itemSize, [this.normalized = false]) {
    count = array.length ~/ itemSize; <---- I get an Error
    usage = 35044; // gl.STATIC_DRAW
  }
}

The error says: 
The getter 'length' isn't defined for the type 'TypedData'.
Try importing the library that defines 'length', correcting the name to the name of an existing getter, or defining a getter or field named 'length'.dartundefined_getter


CodePudding user response:

That should be TypedData:

TypedData array = UInt8List(...);

Know, however, that the base type TypedData doesn't expose many members, only the properties buffer, elementSizeInBytes, lengthInBytes, and offsetInBytes. I don't know how useful that will be, and depending on your purposes might be an overkill amount of abstraction.

  •  Tags:  
  • dart
  • Related