2024-06-14 14:27:56 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:excel/excel.dart';
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-06-14 17:22:52 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-06-14 14:27:56 +08:00
|
|
|
|
|
|
|
class OrderList extends StatefulWidget {
|
|
|
|
const OrderList({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<OrderList> createState() => _OrderListState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _OrderListState extends State<OrderList> {
|
|
|
|
final List lst = [];
|
|
|
|
List<String> headers = [];
|
2024-06-14 17:22:52 +08:00
|
|
|
List<List<dynamic>> data = [];
|
|
|
|
|
2024-06-14 14:27:56 +08:00
|
|
|
ScrollController scrollController = ScrollController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
title: const Text("test"),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
importExcelFile();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.add_circle)),
|
|
|
|
IconButton(onPressed: () {}, icon: const Icon(Icons.output))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
// color: Colors.white,
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Card(
|
|
|
|
color: Colors.white,
|
|
|
|
margin: EdgeInsets.zero,
|
|
|
|
child: headers.isNotEmpty
|
2024-06-14 17:22:52 +08:00
|
|
|
? /*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"),
|
2024-06-14 14:27:56 +08:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String> importExcelFile() async {
|
|
|
|
FilePickerResult? result = await FilePicker.platform
|
|
|
|
.pickFiles(type: FileType.custom, allowedExtensions: ["xlsx", "xls"]);
|
|
|
|
if (result != null) {
|
|
|
|
File file = File(result.files.single.path!);
|
|
|
|
var bytes = file.readAsBytesSync();
|
|
|
|
Excel excel = Excel.decodeBytes(bytes);
|
|
|
|
String tableKey = excel.tables.keys.first;
|
|
|
|
List<String> _headers = excel.tables[tableKey]?.rows.first.map((el) {
|
|
|
|
return el?.value.toString() ?? "";
|
|
|
|
}).toList() ??
|
|
|
|
[];
|
2024-06-14 17:22:52 +08:00
|
|
|
List<List<dynamic>> _data =
|
|
|
|
excel.tables[tableKey]?.rows.sublist(1).map((row) {
|
|
|
|
return row.map((col) {
|
|
|
|
return col?.value ?? "";
|
|
|
|
}).toList();
|
|
|
|
}).toList() ??
|
|
|
|
[];
|
2024-06-14 14:27:56 +08:00
|
|
|
setState(() {
|
|
|
|
headers = _headers;
|
2024-06-14 17:22:52 +08:00
|
|
|
data = _data;
|
2024-06-14 14:27:56 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// 取消选择
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|