import 'package:flutter/material.dart'; import 'dart:convert'; import 'package:json_table/json_table.dart'; class SimpleTable extends StatefulWidget { @override _SimpleTableState createState() => _SimpleTableState(); } class _SimpleTableState extends State { final String jsonSample = '[{"id":"0","name":"Dr.Collazo","Oficina":"A","Phone":"787-522-0123","Espe":"Dentist"},{"id":"1","name":"Dr.Lelolelo","Oficina":"B","Phone":"787-533-4567","Espe":"Dentist"},{"id":"2","name":"Dr.Pepo","Oficina":"C","Phone":"787-544-8910","Espe":"otorrinolaringologo"}]'; bool toggle = true; @override Widget build(BuildContext context) { var json = jsonDecode(jsonSample); return Scaffold( body: Container( padding: EdgeInsets.all(16.0), child: toggle ? Column( children: [ JsonTable( json, showColumnToggle: true, tableHeaderBuilder: (String header) { return Container( padding: EdgeInsets.symmetric( horizontal: 8.0, vertical: 4.0), decoration: BoxDecoration( border: Border.all(width: 0.5), color: Colors.grey[300]), child: Text( header, textAlign: TextAlign.center, style: Theme.of(context).textTheme.display1.copyWith( fontWeight: FontWeight.w700, fontSize: 14.0, color: Colors.black87), ), ); }, tableCellBuilder: (value) { return Container( padding: EdgeInsets.symmetric( horizontal: 4.0, vertical: 2.0), decoration: BoxDecoration( border: Border.all( width: 0.5, color: Colors.grey.withOpacity(0.5))), child: Text( value, textAlign: TextAlign.center, style: Theme.of(context).textTheme.display1.copyWith( fontSize: 14.0, color: Colors.grey[900]), ), ); }, allowRowHighlight: true, rowHighlightColor: Colors.yellow[500].withOpacity(0.7), paginationRowCount: 20, ), SizedBox( height: 20.0, ), Text("Simple table which creates table directly from json") ], ) : Center( child: Text(getPrettyJSONString(jsonSample)), ), ), floatingActionButton: FloatingActionButton( child: Icon(Icons.grid_on), onPressed: () { setState( () { toggle = !toggle; }, ); }), ); } String getPrettyJSONString(jsonObject) { JsonEncoder encoder = new JsonEncoder.withIndent(' '); String jsonString = encoder.convert(json.decode(jsonObject)); return jsonString; } } void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: SimpleTable(), ); } }