build method
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
contextusing BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
//DataTableSource tabledata;
//int actionBtnCnts = 0;
return Consumer<DataModel>(builder: (context, datamodel, child) {
dynamic tableName = _param[gName];
dynamic tableInfo = datamodel.tableList[tableName];
//List columns = tableInfo[gColumns];
//datamodel.setTableDataSearch(tableName, context, _param[gOther]);
//tabledata = TableData(tableInfo, context, datamodel);
/*sortTable(int columnIndex, bool ascending) {
int sortIndex = (columnIndex - actionBtnCnts);
ascending = datamodel.tableList[tableName]![gAscending] ?? ascending;
datamodel.tableSort(tableName, sortIndex, ascending, context);
datamodel.myNotifyListeners();
}
getTableColumns() {
List<DataColumn> result = [];
actionBtnCnts = 0;
for (int i = 0; i < columns.length; i++) {
if (datamodel.isHiddenColumn(columns, i)) {
continue;
}
dynamic col = columns[i];
if (!isNull(col[gShowrange]) && col[gShowrange] != gTable) {
continue;
}
result.add(DataColumn(
label: MyLabel({gLabel: columns[i][gLabel]}, Colors.white.value),
onSort: sortTable));
}
return result;
}
getShowIndex(sortColumnIndex) {
int result = 0;
for (int i = 0; i < columns.length; i++) {
if (datamodel.isHiddenColumn(columns, i)) {
continue;
}
dynamic col = columns[i];
if (!isNull(col[gShowrange]) && col[gShowrange] != gTable) {
continue;
}
if (result == sortColumnIndex) {
return result;
}
result++;
}
return result;
}
getCanvasImage(tablename, context){
Widget customPaint = CustomPaint(size: const Size(300,300),painter: TmpPainter(tablename,datamodel,10,20));
return Container(color: Colors.white, child: Center( child:customPaint));
}
getCanvasImage1(tablename, context) {
List tableData = datamodel.getTableDataMap(tablename, null);
int pageRow = 2000;
int maxRow = 2000;
int dataLength = tableData.length;
if(dataLength > maxRow){
dataLength = maxRow;
}
Widget customPaint = CustomPaint(size: Size(300,pageRow* 20.0),painter: TmpPainter(tableData,datamodel,0, dataLength));
// Widget wColumn = CustomScrollView(slivers: innerLists);
//Widget wBody = Column(children: [datamodel.getTableHeader(tableName, context),Expanded(child:wColumn)],);
Widget wBody = Column(children: [datamodel.getTableHeader(tableName, context),Expanded(child:customPaint)],);
//print('---- begin to show data, 1');
//return SizedBox(height:MediaQuery.of(context).size.height - 135.0 ,width: MediaQuery.of(context).size.width - 15.0,child: wBody);
return SizedBox(height:pageRow* 20.0 + 135.0 ,width: MediaQuery.of(context).size.width - 15.0,child: wBody);
}*/
getDataColRows(tablename, context){
int pageRow = (datamodel.getRowsPerPage(tableInfo, context) * 100 /89).toInt();
//print('pageRow is $pageRow');
List<Widget> rowList = [];
rowList.add(const SizedBox(height:5.0));
List<Widget> actionList = [];
int rowCurrent = tableInfo[gRowCurrent] ?? 0;
//print('----rowCurrentis $rowCurrent');
List tableData = datamodel.getTableDataMap(tablename, null);
Widget action0 = const SizedBox();
if(rowCurrent > 0){
action0 = OutlinedButton(onPressed:(){
tableInfo[gRowCurrent] -= pageRow;
if(tableInfo[gRowCurrent] < 0){
tableInfo[gRowCurrent] = 0;
}
//print('----tableInfo[gRowCurrent] is ${tableInfo[gRowCurrent]}');
datamodel.myNotifyListeners();
}, child: const Text(' < '));
}
int rowCurrentEnd = rowCurrent + pageRow - 1;
if(rowCurrentEnd >= tableData.length){
rowCurrentEnd = tableData.length - 1;
}
Widget action1 = Text('${(rowCurrent + 1)} - ${rowCurrentEnd + 1} of ${tableData.length}');
int maxRow0 = ((tableData.length - 1) ~/ pageRow) * pageRow ;
Widget action2 = const SizedBox();
if(rowCurrent < maxRow0){
action2 = OutlinedButton(onPressed:(){
tableInfo[gRowCurrent] = (tableInfo[gRowCurrent] ?? 0) + pageRow;
if(tableInfo[gRowCurrent] > maxRow0){
tableInfo[gRowCurrent] = maxRow0;
}
//print('----tableInfo[gRowCurrent] is ${tableInfo[gRowCurrent]}');
datamodel.myNotifyListeners();
}, child: const Text(' > '));
}
//tableInfo[gRowCurrent] = e;
actionList.add(action1);
actionList.add(action0);
actionList.add(action2);
Widget rowActions = Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: actionList,);
rowList.add(const Divider(thickness:1));
var sDate = datamodel.getSCurrent('Date');
var sAmount = datamodel.getSCurrent('Amount');
var sTip = datamodel.getSCurrent('Tip');
rowList.add( Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [Text('$sDate'),Text('$sAmount'), Text('$sTip')]));
rowList.add(const Divider(thickness:1));
for(int i = rowCurrent; i <= rowCurrentEnd; i++){
dynamic dataRow = tableData[i];
dynamic entrytime = datamodel.toLocalTime( dataRow[gEntrytime]);
dynamic amount = toMoney( dataRow[gAmount]);
dynamic tip = toMoney( dataRow[gTip]);
//Widget wRow = Text('$entrytime $amount $tip');
Widget wRow = Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [Text('$entrytime'), Text('$amount'), Text('$tip')],);
rowList.add(wRow);
//rowList.add(const Divider(thickness:1));
}
if(tableData.isNotEmpty){
rowList.add(const Divider(thickness:1));
rowList.add(rowActions);
}
Widget customCol = Column(children:rowList);
Widget wBody = Column(children: [datamodel.getTableHeader(tableName, context),Expanded(child:customCol)],);
return SizedBox(height:pageRow* 20.0 + 220.0 ,width: MediaQuery.of(context).size.width - 15.0,child: wBody);
}
//Widget w = getCanvasImage1(tableName, context);
Widget w = getDataColRows(tableName, context);
//print('---- begin to show data,2');
return w;
/*int rowsperpage = datamodel.getRowsPerPage(tableInfo, context);
List<Widget> childList = [];
List tableData = datamodel.getTableDataMap(tableName, context);
List<SliverList> innerLists = [];
const numberOfItemsPerList = 1000;
int numLists = (tableData.length + 999) ~/ numberOfItemsPerList;
print('---- begin to show data,0');
for(int i = 0; i < numLists; i++){
final innerList = <Widget>[];
print('---- begin to show data,00');
for(int j = 0; j < numberOfItemsPerList; j++){
int iRow = i * numberOfItemsPerList + j;
//Size boxSize = const Size(100,100);
double top = 10.0;
if(iRow < tableData.length){
dynamic dataRow = tableData[iRow];
dynamic entrytime = datamodel.toLocalTime( dataRow[gEntrytime]);
dynamic amount = toMoney( dataRow[gAmount]);
dynamic tip = toMoney( dataRow[gTip]);
/*
Widget rowW = Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text('$entrytime'),Text('$amount'),Text('$tip')],);*/
Widget rowW = Text('$entrytime $amount $tip');
innerList.add(rowW);
}
}
innerLists.add(
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index)=> innerList[index],
childCount: innerList.length
),),
);
}.
print('---- begin to show data,1');
//Widget wColumn = Column(children: childList);
//Widget wColumn = CustomScrollView(slivers: innerLists);
Widget wBody = Column(children: [datamodel.getTableHeader(tableName, context),Expanded(child:wColumn)],);
print('---- begin to show data,2');
int rowsperpage = datamodel.getRowsPerPage(tableInfo, context);
print('---- begin to show data, data length is ${tableData.length}');
return SizedBox(height:MediaQuery.of(context).size.height - 135.0 ,width: MediaQuery.of(context).size.width - 15.0,child: wBody);*/
//print('======= paint paginaeddatatable');*/
/* int showIndex = getShowIndex(tableInfo[gSortColumnIndex]);
dynamic tableColumns = getTableColumns();
//Widget wHeader = SizedBox();
Widget wHeader = datamodel.getTableHeader(tableName, context);
PaginatedDataTable paginatedDataTable = PaginatedDataTable(
key: tableInfo[gKey],
rowsPerPage: rowsperpage,
availableRowsPerPage: const [
10,
20,
30,
40,
50
], //const [5, 10, 15, 20, 50],
onPageChanged: (e) {
tableInfo[gRowCurrent] = e;
},
initialFirstRowIndex: tableInfo[gRowCurrent],
//actions: [Text('action0'), Text('action1')],
/*onRowsPerPageChanged: (int v) {
//widget.onRowsPerPageChanged?.call(v ?? 10);
//datamodel.setRowsPerPage(tableInfo, v);
},*/
columns: tableColumns,
columnSpacing: 15,
//horizontalMargin: 2,
//dataRowMinHeight: 30.0,
dataRowMaxHeight: gTableMaxHeight,
dataRowMinHeight: 15.0,
source: tabledata,
showCheckboxColumn: true,
sortAscending: tableInfo[gAscending],
sortColumnIndex: actionBtnCnts + showIndex,
header: wHeader,
);
return paginatedDataTable;*/
});
}