init
This commit is contained in:
123
lib/order_list.dart
Normal file
123
lib/order_list.dart
Normal file
@ -0,0 +1,123 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:excel/excel.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class OrderList extends StatefulWidget {
|
||||
const OrderList({super.key});
|
||||
|
||||
@override
|
||||
State<OrderList> createState() => _OrderListState();
|
||||
}
|
||||
|
||||
class _OrderListState extends State<OrderList> {
|
||||
final List lst = [];
|
||||
List<String> headers = [];
|
||||
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
|
||||
? 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"),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
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() ??
|
||||
[];
|
||||
setState(() {
|
||||
headers = _headers;
|
||||
});
|
||||
} else {
|
||||
// 取消选择
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user