/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_datagrid-20.4.48/lib/src/datagrid_widget/widgets/cell_widget.dart:700:31: Error: Property 'context' cannot be accessed on 'OverlayState?' because it is potentially null.
- 'OverlayState' is from 'package:flutter/src/widgets/overlay.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/overlay.dart').
Try accessing using ?. instead.
import 'package:flutter/material.dart';
import 'package:medical_shop_management/data/product_data.dart';
import 'package:medical_shop_management/models/products.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
import 'package:firebase_database/firebase_database.dart';
class TablePage extends StatefulWidget {
const TablePage({super.key});
@override
State<TablePage> createState() => _TablePageState();
}
class _TablePageState extends State<TablePage> {
late ProductDataSource productDataSource;
List<Products> productData = [];
getDataFromDatabase() async {
var value = FirebaseDatabase.instance.ref();
var getValue = await value.child('shop_produc').once();
return getValue;
}
Widget _buildDataGrid() {
return FutureBuilder(
future: getDataFromDatabase(),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasData) {
var showData = snapshot.data;
Map<dynamic, dynamic> values = showData.value;
List<dynamic> key = values.keys.toList();
for (int i = 0; i < key.length; i++) {
final data = values[key[i]];
productData.add(
Products(
id: data['id'],
hsn: data['hsn'],
// exp_date: data['exp_date'],
// item_desc: data['item_desc'],
// mrp: data['mrp'],
// pack: data['pack'],
// quantity: data['quantity'],
),
);
}
productDataSource = ProductDataSource(productData);
return SfDataGrid(
source: productDataSource,
columns: <GridColumn>[
GridColumn(
columnName: 'id',
label: Container(
padding: EdgeInsets.all(16.0),
alignment: Alignment.center,
child: Text(
'ID',
))),
GridColumn(
columnName: 'name',
label: Container(
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text('Name'))),
GridColumn(
columnName: 'designation',
label: Container(
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text(
'Designation',
overflow: TextOverflow.ellipsis,
))),
GridColumn(
columnName: 'salary',
label: Container(
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text('Salary'))),
],
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
);
}
@override
void initState() {
super.initState();
getDataFromDatabase();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Syncfusion flutter datagrid firebase demo'),
),
body: _buildDataGrid(),
);
}
}