2

can you help me please. I'm new in Flutter and i try to use share plugin. That works well. I created a list of products in my app.

Share.share(widget.selectedList.productsAndStatus.toString());

And when i copy that, it shows like this:

[{productName: Dawd, productDescription: , productStatus: false}, {productName: Skap, productDescription: , productStatus: false}]

Is there any way to make it copy only name of product and description of product without '[, ], {, }, productName, productDescription, productStatus' ?

Marek
  • 201
  • 1
  • 4
  • 14
  • Does this answer your question? [Default stringify for objects, equivalent to Java's toString?](https://stackoverflow.com/questions/22921222/default-stringify-for-objects-equivalent-to-javas-tostring) – easeccy Apr 08 '21 at 10:25

1 Answers1

1

Do something like below.

class Product {
  static int counter = 0;
  final int _id = ++counter;
  final String? name;
  Product({this.name});
  @override
  String toString() => '$name with id $_id';
}

void main() {
  Product p1 = Product(name: 'Computer');
  Product p2 = Product(name: 'Refrigerator');
  print(p1.toString());
  print(p2.toString()); 
}

Output:

Computer with id 1
Refrigerator with id 2
Second Person Shooter
  • 14,188
  • 21
  • 90
  • 165