How can I view the Flutter DataTable on Drive using a web browser without downloading?
In this article, we will explore the steps to visualize Flutter DataGrid hosted on Google Drive without the hassle of downloading and opening files on your local machine.
Initialize the SfDataGrid widget with all the required properties. The exportToPdfDocument method is invoked on the current state of the key to export the data from the SfDataGrid as a PdfDocument. A URL for the PDF is created using Blob and createObjectUrl, where the PDF bytes are passed along with the MIME type of application/pdf. The open method is utilized to open the URL in a new browser tab.
final GlobalKey<SfDataGridState> _key = GlobalKey<SfDataGridState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('SfDatagrid Demo')),
body: Column(children: [
const Padding(padding: EdgeInsets.only(top: 30)),
SizedBox(
child: ElevatedButton.icon(
onPressed: () async {
final PdfDocument document =
_key.currentState!.exportToPdfDocument();
final List<int> data = document.saveSync();
Uint8List bytes = Uint8List.fromList(data);
final url = html.Url.createObjectUrl(
html.Blob([bytes], 'application/pdf'));
html.window.open(url, '_blank');
document.dispose();
},
icon: const Icon(Icons.print),
label: const Text('Export DataGrid to PDF'),
)),
Expanded(
child: Card(
margin: const EdgeInsets.all(30),
child: SfDataGrid(
source: _employeeDataSource,
key: _key,
columns: getColumns,
columnWidthMode: ColumnWidthMode.fill),
))
]));
}
}
Conclusion
I hope you enjoyed learning about how to view the Flutter DataTable on Drive using a web browser without downloading.
You can refer to our Flutter DataGrid’s feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter DataGrid documentation to understand how to present and manipulate data.
For current customers, you can check out our Flutter components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our Flutter DataGrid and other Flutter components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!