3

I'm developing a table at Flatter.

In order to process selection/unselection for each row of the table, I would like to develop a Checkbox for the header of the table and all rows.

Then, I found the showCheckboxColumn option in the DataTable widget and applied it with pleasure.

However, as shown in the picture below, the Checkbox was not applied at all, and I can't find the cause.

enter image description here

The DataTable widget I designed is written like the following code:

@override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(24, 34, 24, 24),
      child: Scrollbar(
        trackVisibility: true,
        child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                'Selected Delete',
              ),
              SingleChildScrollView(
                padding: EdgeInsets.only(top: 19),
                scrollDirection: Axis.vertical,
                child: DataTable(
                  showCheckboxColumn: true,
                  headingRowColor: MaterialStateProperty.all(Color(0xFFEEEEEE)),
                  rows: _getTableDatas(),
                  columns: _getTableHeaders(),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

Is there any part of this code that I'm wrong about or I'm wrong about the concept of DataTable?

1 Answer 1

3

According to the docs,, You need to add showCheckboxColumn property to make the row selectable. Try adding and do let me know.

Sign up to request clarification or add additional context in comments.

3 Comments

OMG.... your answer is perfect! For each rows I added onSelectChanged option like this DataRow( cells: cellList, onSelectChanged: (bool? selected) { selected == null ? print('selected is null') : print('select is $selected'); }, ), Then, a checkbox was appeared! Thank you so much
Always a pleasure, helping others :)
@SahilHariyani proper answer please with code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.