This commit is contained in:
quantulr
2024-06-14 17:22:52 +08:00
parent 825b94b8c3
commit 62a7c7f29e
6 changed files with 160 additions and 57 deletions

View File

@ -1,9 +1,9 @@
import 'dart:ffi';
import 'dart:io';
import 'package:excel/excel.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class OrderList extends StatefulWidget {
const OrderList({super.key});
@ -15,6 +15,8 @@ class OrderList extends StatefulWidget {
class _OrderListState extends State<OrderList> {
final List lst = [];
List<String> headers = [];
List<List<dynamic>> data = [];
ScrollController scrollController = ScrollController();
@override
@ -43,57 +45,78 @@ class _OrderListState extends State<OrderList> {
color: Colors.white,
margin: EdgeInsets.zero,
child: headers.isNotEmpty
? Scrollbar(
controller: scrollController,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(12.0),
child: DataTable(
columns: headers.map((el) {
return DataColumn(label: Text(el));
}).toList() /*const [
DataColumn(
label: Text(
"下单时间",
)),
DataColumn(
label: Text(
"物流公司",
)),
DataColumn(
label: Text(
"付款方式",
)),
DataColumn(
label: Text(
"金额",
)),
DataColumn(
label: Text(
"物流包裹",
)),
DataColumn(
label: Text(
"操作",
textAlign: TextAlign.center,
)),
]*/
,
rows: [], /* rows: [
DataRow(cells: [
const DataCell(Text("2024-01-12")),
const DataCell(Text("圆通速递")),
const DataCell(Text("套餐券")),
const DataCell(Text("12")),
DataCell(ElevatedButton(
onPressed: () {}, child: const Text("编辑包裹"))),
DataCell(ElevatedButton(
onPressed: () {}, child: const Text("编辑"))),
]),
]*/
),
))
: Text("empty"),
? /*Scrollbar(
// controller: scrollController,
child:*/
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(12.0),
child: DataTable(
columns: headers.map((el) {
return DataColumn(label: Text(el));
}).toList(),
rows: data.map((row) {
return DataRow(
cells: row.asMap().entries.map((col) {
String col_title = headers[col.key];
return DataCell(col_title == "物流名称"
? Row(
children: [
Text("${col.value}"),
IconButton(
// padding: EdgeInsets.all(2),
iconSize: 12,
onPressed: () {
// Dialog()
showDialog(
context: context,
builder: (BuildContext
context) =>
AlertDialog(
// icon: const Icon(Icons.edit),
title: const Text(
"填写物流公司"),
content: const Column(
mainAxisSize:
MainAxisSize.min,
children: [
TextField(
decoration:
InputDecoration(
labelText:
"物流公司"),
)
],
),
actions: [
ElevatedButton(
onPressed: () {},
child: const Text(
"取消")),
ElevatedButton(
onPressed: () {},
child: const Text(
"确认")),
],
));
},
icon: const Icon(Icons.edit))
],
)
: col_title == "物流信息"
? ElevatedButton(
onPressed: () {
context.push("/logistics");
},
child: const Text("填写"),
)
: Text("${col.value}"));
}).toList());
}).toList(),
),
)
/*)*/
: const Text("empty"),
)
],
),
@ -112,8 +135,16 @@ class _OrderListState extends State<OrderList> {
return el?.value.toString() ?? "";
}).toList() ??
[];
List<List<dynamic>> _data =
excel.tables[tableKey]?.rows.sublist(1).map((row) {
return row.map((col) {
return col?.value ?? "";
}).toList();
}).toList() ??
[];
setState(() {
headers = _headers;
data = _data;
});
} else {
// 取消选择