작업을 하다가 3~4회정도 중복 클래스에서 변경하기 귀찮은 내용이 생겨서 문제가 더 커지기 전에 처리
추가로 더 만들어야할 내용은 굳이 처리하지 않았음. 필요시 처리하면 될듯해서..
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
syncfusion_flutter_datagrid: ^20.2.46
intl: ^0.17.0
import 'package:flutter/material.dart';
import 'package:simple/utils/custom/custom_grid_column.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
abstract class ParentDataGrid<Model, Service> extends DataGridSource {
ParentDataGrid(this.modelList, this.service, this._dataGridController) {
customGridColumn = CustomGridColumn();
buildDataGridRow();
}
late final DataGridController _dataGridController;
TextEditingController editingController = TextEditingController();
List<DataGridRow> dataGridRows = [];
List<Model> modelList = [];
late CustomGridColumn customGridColumn;
late Service service;
dynamic newCellValue;
final int _rowsPerPage = 15;
final double _dataPagerHeight = 60.0;
@override
List<DataGridRow> get rows => dataGridRows;
@override
Future<void> handleRefresh() async {
buildDataGridRow();
notifyListeners();
}
@override
void onCellSubmit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex, GridColumn column);
@override
Widget? buildEditWidget(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex, GridColumn column, CellSubmit submitCell);
void buildDataGridRow();
List<GridColumn> getColumns();
}
import 'package:flutter/material.dart';
import 'package:simple/datagrid/parent/parent_datagrid.dart';
import 'package:simple/model/estimate/estimate_model.dart';
import 'package:simple/services/estimate/estimate_service.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
class EstimateDataGrid extends ParentDataGrid<EstimateModel, EstimateService> {
EstimateDataGrid(super.modelList, super.service, super.dataGridController);
@override
void buildDataGridRow() {
dataGridRows = super.modelList.map<DataGridRow>((dataGridRow) {
return DataGridRow(cells: [
DataGridCell<String>(columnName: 'name', value: dataGridRow.name),
/*DataGridCell<String>(columnName: 'number', value: dataGridRow.number),
DataGridCell<String>(columnName: 'registrationNumber', value: dataGridRow.registrationNumber),
DataGridCell<String>(columnName: 'conditions', value: dataGridRow.conditions),
DataGridCell<String>(columnName: 'type', value: dataGridRow.type),*/
const DataGridCell<Widget>(columnName: 'update', value: null),
const DataGridCell<Widget>(columnName: 'delete', value: null),
]);
}).toList(growable: false);
}
@override
DataGridRowAdapter? buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((dataGridCell) {
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child:
dataGridCell.columnName == "update" || dataGridCell.columnName.contains("delete")
? LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return ElevatedButton(
onPressed: () async {
String name = row.getCells()[0].value.toString();
String number = row.getCells()[1].value.toString();
String registrationNumber = row.getCells()[2].value.toString();
if(dataGridCell.columnName == "update") {
} else {
/*bool isDeleteResult = await customerService.delete(name, number, registrationNumber);
if(isDeleteResult) {
//https://help.syncfusion.com/flutter/datagrid/selection
customerModelList.removeWhere((element) => element.name == name && element.number == number && element.registrationNumber == registrationNumber);
await handleRefresh();
}*/
}
},
child: dataGridCell.columnName == "update" ? const Text('수정') : const Text('삭제'));
})
: Text(dataGridCell.value.toString(), overflow: TextOverflow.ellipsis)
);
}).toList());
}
@override
void onCellSubmit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex, GridColumn column) {
}
@override
Widget? buildEditWidget(DataGridRow dataGridRow,
RowColumnIndex rowColumnIndex, GridColumn column, CellSubmit submitCell) {
return null;
}
@override
List<GridColumn> getColumns() {
return <GridColumn>[
customGridColumn.getCustomGridColumn("name", "상호", alignment: Alignment.center),
customGridColumn.getCustomGridColumn("update", "수정"),
customGridColumn.getCustomGridColumn("delete", "삭제"),
];
}
}
import 'package:json_annotation/json_annotation.dart';
@JsonSerializable()
class EstimateModel {
@JsonKey(name: "name")
String name;
EstimateModel({
required this.name,
});
factory EstimateModel.fromJson(Map<String, dynamic> json) {
return EstimateModel(
name: json['name'],
);
}
Map<String, dynamic> toJson() {
final map = <String, dynamic> {
'name' : name,
};
return map;
}
@override
String toString() {
StringBuffer buffer = StringBuffer();
buffer.write("상호: $name \n");
return buffer.toString();
}
}
import 'package:flutter/material.dart';
import 'package:simple/commons/text/text_information.dart';
import 'package:simple/model/estimate/estimate_model.dart';
import 'package:simple/model/estimate/estimate_model_list.dart';
import 'package:simple/model/http/http_header_model.dart';
import 'package:simple/model/http/http_response_result.dart';
import 'package:simple/utils/dialog/custom_dialog.dart';
import 'package:simple/utils/dialog/dialog_action.dart';
import 'package:simple/utils/http/http_request.dart';
import 'package:simple/utils/http/http_url.dart';
class EstimateService {
final BuildContext context;
EstimateService(this.context);
}