I have an issue with updating the UI right after popupmenu is dismissed. The item being clicked actually is being deleted but updating it is the problem. I understand that I am calling this method from an unstatefull class that extends DatatableSource.
Here is the code: 1: Datasource
class ResultDataSource extends DataTableSource{
//Dependency injection
var brandsController = BrandsController(BrandsRepository());
ResultDataSource({
@required List<Result> resultData,
@required this.onRowSelect,
}) : _resultData = resultData,
assert(resultData != null);
final List<Result> _resultData;
final OnRowSelect onRowSelect;
@override
DataRow getRow(int index) {
assert(index >= 0);
if (index >= _resultData.length) {
return null;
}
final _result = _resultData[index];
return DataRow.byIndex(
index: index, // DONT MISS THIS
cells: <DataCell>[
DataCell(Text('${_result.name}',style: TextStyle(fontSize: 13.0, fontWeight: FontWeight.w600, color: secondaryColor))),
DataCell(Text('${_result.country}',style: TextStyle(fontSize: 13.0, color: secondaryColor))),
DataCell(Text('${_result.isActive.toString() == "true" ? "Active" : "Inactive"}',style: TextStyle(fontSize: 13.0, fontWeight: FontWeight.w500, color: primaryColor),)),
DataCell(
FutureBuilder<List<Result>>(
future: brandsController.fetchBrandList(),
builder: (context, snapshot){
return PopupMenuButton(
elevation: 20.0,
icon: Icon(
Icons.more_horiz,
color: secondaryColor.withOpacity(0.5),
),
itemBuilder: (context) =>[
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset("assets/icons/view.svg", height: 18.0,color: Colors.blueGrey, ),
SizedBox(width:10.0),
Text("View Details", style: TextStyle(color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 1,
),
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset("assets/icons/repeat.svg", height: 18.0,color: Colors.blueGrey, ),
SizedBox(width:10.0),
Text("Orders", style: TextStyle(color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 2,
),
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset("assets/icons/activities.svg", height: 18.0,color: Colors.blueGrey, ),
SizedBox(width:10.0),
Text("Activities", style: TextStyle(color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 3,
),
PopupMenuItem(
onTap: () {
//Here is the delete functionality
brandsController.deleteBrand(_result.id.toString());
},
child:Row(
children: [
SvgPicture.asset("assets/icons/garbage.svg", height: 18.0,color: Colors.blueGrey, ),
SizedBox(width:10.0),
Text("Delete", style: TextStyle(color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 4,
),
],
);
},
)
),
],
);
}
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => _resultData.length;
@override
int get selectedRowCount => 0;
}
2: Code from Statefull widget class
ListView(
padding: const EdgeInsets.all(16),
shrinkWrap: true,
children: [
Theme(
data: Theme.of(context).copyWith(
dividerColor: Colors.blueGrey.shade100.withOpacity(0.4),
),
child: PaginatedDataTable(
rowsPerPage: snapshot.data.length ?? 1,
showCheckboxColumn: true,
dataRowHeight: 60,
columns: [
DataColumn(label: Text(
"Name",
style: TextStyle(
fontSize: 13.5,
color: secondaryColor.withOpacity(0.4)),
),),
DataColumn(label: Text(
"Country",
style: TextStyle(
fontSize: 13.5,
color: secondaryColor.withOpacity(0.4)),
),),
DataColumn(label: Text(
"Status",
style: TextStyle(
fontSize: 13.5,
color: secondaryColor.withOpacity(0.4)),
),),
DataColumn(label: PopupMenuButton(
elevation: 20.0,
icon: Icon(
Icons.more_horiz,
color: secondaryColor.withOpacity(0.5),
),
itemBuilder: (context) =>
[
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset(
"assets/icons/view.svg", height: 18.0,
color: Colors.blueGrey,),
SizedBox(width: 10.0),
Text("View Details", style: TextStyle(
color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 1,
),
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset(
"assets/icons/repeat.svg", height: 18.0,
color: Colors.blueGrey,),
SizedBox(width: 10.0),
Text("Orders", style: TextStyle(
color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 2,
),
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset(
"assets/icons/activities.svg", height: 18.0,
color: Colors.blueGrey,),
SizedBox(width: 10.0),
Text("Activities", style: TextStyle(
color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 3,
),
PopupMenuItem(
child: Row(
children: [
SvgPicture.asset(
"assets/icons/garbage.svg", height: 18.0,
color: Colors.blueGrey,),
SizedBox(width: 10.0),
Text("Delete", style: TextStyle(
color: Colors.blueGrey, fontSize: 13.0),)
],
),
value: 4,
),
],
)),
],
source: ResultDataSource(
onRowSelect: (index) => () {},
resultData: snapshot.data,
),
),
),
],
),