We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Giving runtime eror

/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.

          Overlay.of(context).context.findRenderObject()! as RenderBox;

                              ^^^^^^^

Giving error on running the program!

DataTable.dart

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(),
    );
  }
}


1 Reply

TP Tamilarasan Paranthaman Syncfusion Team February 6, 2023 06:01 AM UTC

Hi Mobashshirur,


Based on the information you have provided, it appears that you may be using an outdated version of the Flutter SDK. I have tested the DataGrid using the latest version (3.7.1) and have not encountered the issue you have described.


To help resolve the issue you are experiencing, we recommend upgrading your Flutter SDK to the latest stable version (3.7.1). This may resolve the issue you are experiencing.


Regards,

Tamilarasan


Loader.
Up arrow icon