Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print an Instance?

Tags:

flutter

dart

i'm trying to print an SMS, but i'm just printing "instance of..."

this is an app which show all sms in the smartphone on the display

i'm using the sms plugin

class _HomeState extends State<Home> {


  Future<List> getSMS() async {


  SmsQuery query = new SmsQuery();
  List<SmsMessage> messages = await query.getAllSms;



  return messages;
}

  @override
    void initState() {
    super.initState();
}




@override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: FutureBuilder<List>(
      future: getSMS(),
      builder: (context, snapshot) {
       switch(snapshot.connectionState){
        case ConnectionState.none:
        case ConnectionState.waiting:

        default:
            if(snapshot.hasError){
              return new Center(
                  child: Text("Erro ao Carregar Dados :(",
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 25.0),
                    textAlign: TextAlign.center,)
              );
            } else {
            debugPrint(snapshot.data[0].toString());
          }
      }
        return new Center(
          child: Text(snapshot.data[0].toString(),
          style: TextStyle(
            color: Colors.black,
            fontSize: 25.0),
             textAlign: TextAlign.center,)
          );
       },
     ),
   );
 }
}

all i need is to print the sms on display, but i don't know how to print an instance of object in dart

like image 259
Gustavo Oliveira Avatar asked Oct 25 '25 02:10

Gustavo Oliveira


1 Answers

use .toJson() instead of .toString()

like image 133
Somwang Souksavatd Avatar answered Oct 26 '25 18:10

Somwang Souksavatd