add scroll bar
This commit is contained in:
@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -18,7 +19,10 @@ class Logistics extends StatefulWidget {
|
||||
class _LogisticsState extends State<Logistics> {
|
||||
List<dynamic> goodsList = [];
|
||||
String _orderPayWay = "";
|
||||
|
||||
// String _logistics = "";
|
||||
List _packages = [];
|
||||
bool _packageInit = false;
|
||||
int _activePackage = 0;
|
||||
final TextEditingController _goodsNameController =
|
||||
TextEditingController(text: "");
|
||||
@ -43,6 +47,8 @@ class _LogisticsState extends State<Logistics> {
|
||||
GoRouterState.of(context).uri.queryParameters["orderNumber"];
|
||||
String? orderPayWay =
|
||||
GoRouterState.of(context).uri.queryParameters["orderPayWay"];
|
||||
String? logistics =
|
||||
GoRouterState.of(context).uri.queryParameters["logistics"];
|
||||
_orderPayWay = orderPayWay!;
|
||||
|
||||
if (orderNumber?.isEmpty ?? true) {
|
||||
@ -54,6 +60,30 @@ class _LogisticsState extends State<Logistics> {
|
||||
queryParameters: {"orderNumber": orderNumber});
|
||||
});
|
||||
goodsList = response.data["value"];
|
||||
|
||||
if (logistics != null && logistics.isNotEmpty && !_packageInit) {
|
||||
try {
|
||||
List packages = jsonDecode(logistics);
|
||||
|
||||
_packages = packages;
|
||||
|
||||
if (_orderPayWay != "套餐商品") {
|
||||
for (var p in _packages) {
|
||||
p["goods"].forEach((g) {
|
||||
var targetGoods = goodsList
|
||||
.firstWhere((tg) => g["id"] == tg["id"], orElse: () => null);
|
||||
if (targetGoods != null) {
|
||||
targetGoods["goodsNum"] -= g["num"];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
_packageInit = true;
|
||||
} catch (e) {
|
||||
e;
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -73,6 +103,7 @@ class _LogisticsState extends State<Logistics> {
|
||||
if (hasUnAddedGoods) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text("有未添加至包裹的商品"),
|
||||
showCloseIcon: true,
|
||||
backgroundColor: Colors.redAccent,
|
||||
));
|
||||
return;
|
||||
@ -90,6 +121,7 @@ class _LogisticsState extends State<Logistics> {
|
||||
if (!result) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
backgroundColor: Colors.redAccent,
|
||||
showCloseIcon: true,
|
||||
content: Text("有未填写的数据")));
|
||||
return;
|
||||
}
|
||||
@ -184,8 +216,9 @@ class _LogisticsState extends State<Logistics> {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
"请填写完整商品信息")));
|
||||
content: Text("请填写完整商品信息"),
|
||||
showCloseIcon: true,
|
||||
));
|
||||
return;
|
||||
}
|
||||
int goodsNum = int.parse(
|
||||
@ -216,77 +249,89 @@ class _LogisticsState extends State<Logistics> {
|
||||
child: const Text("添加到包裹"))
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: goodsList
|
||||
: goodsList
|
||||
.where((el) => el["goodsNum"] > 0)
|
||||
.length,
|
||||
itemBuilder: (context, index) {
|
||||
final goods = goodsList
|
||||
.where((el) => el["goodsNum"] > 0)
|
||||
.toList()[index];
|
||||
return ListTile(
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
// 检查商品及规格是否已存在于目标包裹
|
||||
int targetIndex = _packages[
|
||||
_activePackage]["goods"]
|
||||
.indexWhere((el) =>
|
||||
el["id"] ==
|
||||
goods["id"] &&
|
||||
goods["wisdGoodsSpec"]
|
||||
["id"] ==
|
||||
el["specId"]);
|
||||
if (targetIndex != -1) {
|
||||
setState(() {
|
||||
_packages[_activePackage]
|
||||
["goods"]
|
||||
[targetIndex]
|
||||
["num"] += 1;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_packages[_activePackage]
|
||||
.isNotEmpty
|
||||
? ListView.builder(
|
||||
itemCount: goodsList
|
||||
.where(
|
||||
(el) => el["goodsNum"] > 0)
|
||||
.length,
|
||||
itemBuilder: (context, index) {
|
||||
final goods = goodsList
|
||||
.where((el) =>
|
||||
el["goodsNum"] > 0)
|
||||
.toList()[index];
|
||||
return ListTile(
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () {
|
||||
// 检查商品及规格是否已存在于目标包裹
|
||||
int targetIndex = _packages[
|
||||
_activePackage]
|
||||
["goods"]
|
||||
.add({
|
||||
"id": goods["id"],
|
||||
"specId":
|
||||
goods["wisdGoodsSpec"]
|
||||
.indexWhere((el) =>
|
||||
el["id"] ==
|
||||
goods["id"] &&
|
||||
goods["wisdGoodsSpec"]
|
||||
["id"] ==
|
||||
el["specId"]);
|
||||
if (targetIndex != -1) {
|
||||
setState(() {
|
||||
_packages[_activePackage]
|
||||
["goods"]
|
||||
[targetIndex]
|
||||
["num"] += 1;
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_packages[_activePackage]
|
||||
["goods"]
|
||||
.add({
|
||||
"id": goods["id"],
|
||||
"specId": goods[
|
||||
"wisdGoodsSpec"]
|
||||
["id"],
|
||||
"name":
|
||||
goods["goodsName"],
|
||||
"spec":
|
||||
goods?["wisdGoodsSpec"]
|
||||
"name": goods[
|
||||
"goodsName"],
|
||||
"spec": goods?[
|
||||
"wisdGoodsSpec"]
|
||||
?[
|
||||
"specName"] ??
|
||||
"",
|
||||
"num": 1
|
||||
});
|
||||
});
|
||||
}
|
||||
var curGoods =
|
||||
goodsList.firstWhere(
|
||||
(el) =>
|
||||
el["id"] ==
|
||||
goods["id"],
|
||||
orElse: () => -1);
|
||||
"num": 1
|
||||
});
|
||||
});
|
||||
}
|
||||
var curGoods =
|
||||
goodsList.firstWhere(
|
||||
(el) =>
|
||||
el["id"] ==
|
||||
goods["id"],
|
||||
orElse: () => -1);
|
||||
|
||||
setState(() {
|
||||
curGoods["goodsNum"] -= 1;
|
||||
});
|
||||
},
|
||||
setState(() {
|
||||
curGoods["goodsNum"] -= 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
leading: Image.network(
|
||||
goods["goodsPhoto"],
|
||||
width: 100,
|
||||
height: 100,
|
||||
),
|
||||
title: Text(
|
||||
"${goods["goodsName"]} - ${goods?["wisdGoodsSpec"]?["specName"] ?? ''}"),
|
||||
subtitle: Text(
|
||||
"数量 : ${goods?["goodsNum"]}"),
|
||||
);
|
||||
})
|
||||
: const Center(
|
||||
child: Icon(
|
||||
CupertinoIcons.circle,
|
||||
size: 36,
|
||||
),
|
||||
leading: Image.network(
|
||||
goods["goodsPhoto"],
|
||||
width: 100,
|
||||
height: 100,
|
||||
),
|
||||
title: Text(
|
||||
"${goods["goodsName"]} - ${goods?["wisdGoodsSpec"]?["specName"] ?? ''}"),
|
||||
subtitle: Text(
|
||||
"数量 : ${goods?["goodsNum"]}"),
|
||||
);
|
||||
})),
|
||||
)),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
@ -300,10 +345,39 @@ class _LogisticsState extends State<Logistics> {
|
||||
itemBuilder:
|
||||
(BuildContext context, int index) {
|
||||
return PackageCard(
|
||||
logisticsNumber: _packages[index]
|
||||
["logisticsNumber"],
|
||||
onDeleteGoods: (goods) {
|
||||
if (goods["num"] == 1) {
|
||||
setState(() {
|
||||
_packages[index]["goods"] =
|
||||
_packages[index]["goods"]
|
||||
.where((el) =>
|
||||
el["id"] !=
|
||||
goods["id"])
|
||||
.toList();
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
goods["num"] -= 1;
|
||||
});
|
||||
}
|
||||
if (_orderPayWay != "套餐商品") {
|
||||
setState(() {
|
||||
goodsList.firstWhere(
|
||||
(e) =>
|
||||
goods["id"] ==
|
||||
e["id"],
|
||||
orElse: () => null)?[
|
||||
"goodsNum"] += 1;
|
||||
});
|
||||
}
|
||||
},
|
||||
onLogisticsChanged: (value) {
|
||||
_packages[index]
|
||||
["logisticsNumber"] = value;
|
||||
},
|
||||
orderPayWay: _orderPayWay,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_activePackage = index;
|
||||
@ -312,6 +386,23 @@ class _LogisticsState extends State<Logistics> {
|
||||
onClose: () {
|
||||
var curId =
|
||||
_packages[index]["id"];
|
||||
if (_orderPayWay != "套餐商品") {
|
||||
_packages[index]["goods"]
|
||||
.forEach((el) {
|
||||
var targetGoods =
|
||||
goodsList.firstWhere(
|
||||
(goodsItem) =>
|
||||
goodsItem["id"] ==
|
||||
el["id"],
|
||||
orElse: () => -1);
|
||||
if (targetGoods != -1) {
|
||||
setState(() {
|
||||
targetGoods["goodsNum"] +=
|
||||
el["num"];
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
_activePackage =
|
||||
_activePackage >= index
|
||||
@ -341,6 +432,7 @@ class _LogisticsState extends State<Logistics> {
|
||||
"goods": []
|
||||
}
|
||||
];
|
||||
_activePackage += 1;
|
||||
});
|
||||
},
|
||||
child: const Text("添加包裹"))
|
||||
@ -351,10 +443,14 @@ class _LogisticsState extends State<Logistics> {
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return const Center(
|
||||
child: Icon(
|
||||
Icons.error_outline,
|
||||
color: Colors.red,
|
||||
size: 60,
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
color: Colors.red,
|
||||
size: 60,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@ -375,21 +471,36 @@ class PackageCard extends StatefulWidget {
|
||||
required this.onLogisticsChanged,
|
||||
required this.totalPackagesCount,
|
||||
required this.onClose,
|
||||
required this.orderPayWay,
|
||||
required this.onDeleteGoods,
|
||||
required this.logisticsNumber,
|
||||
});
|
||||
|
||||
final bool isActive;
|
||||
final Function() onTap;
|
||||
final Function() onClose;
|
||||
final Function(Map<String, dynamic> goods) onDeleteGoods;
|
||||
final Map<String, dynamic> package;
|
||||
final int index;
|
||||
final Function(String) onLogisticsChanged;
|
||||
final int totalPackagesCount;
|
||||
final String orderPayWay;
|
||||
final String logisticsNumber;
|
||||
|
||||
@override
|
||||
State<PackageCard> createState() => _PackageCardState();
|
||||
}
|
||||
|
||||
class _PackageCardState extends State<PackageCard> {
|
||||
final TextEditingController _logisticsController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
_logisticsController.text = widget.logisticsNumber;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
@ -417,6 +528,7 @@ class _PackageCardState extends State<PackageCard> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _logisticsController,
|
||||
onChanged: widget.onLogisticsChanged,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(), labelText: "物流单号"),
|
||||
@ -427,13 +539,26 @@ class _PackageCardState extends State<PackageCard> {
|
||||
DataTable(columns: const [
|
||||
DataColumn(label: Text("名称")),
|
||||
DataColumn(label: Text("规格")),
|
||||
DataColumn(label: Text("数量"))
|
||||
DataColumn(label: Text("数量")),
|
||||
DataColumn(label: Text("操作"))
|
||||
], rows: [
|
||||
for (var goodsItem in widget.package["goods"])
|
||||
for (var goodsItem
|
||||
in widget.package["goods"].asMap().entries)
|
||||
DataRow(cells: [
|
||||
DataCell(Text("${goodsItem["name"]}")),
|
||||
DataCell(Text("${goodsItem["spec"]}")),
|
||||
DataCell(Text("${goodsItem["num"]}")),
|
||||
DataCell(Text("${goodsItem.value["name"]}")),
|
||||
DataCell(Text("${goodsItem.value["spec"]}")),
|
||||
DataCell(Text("${goodsItem.value["num"]}")),
|
||||
DataCell(SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: IconButton(
|
||||
icon: const Icon(CupertinoIcons.delete),
|
||||
iconSize: 16,
|
||||
padding: const EdgeInsets.all(4),
|
||||
onPressed: () {
|
||||
widget.onDeleteGoods(goodsItem.value);
|
||||
}),
|
||||
)),
|
||||
])
|
||||
]),
|
||||
],
|
||||
|
@ -5,6 +5,8 @@ import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class OrderList extends StatefulWidget {
|
||||
const OrderList({super.key});
|
||||
@ -61,155 +63,163 @@ class _OrderListState extends State<OrderList> {
|
||||
Card(
|
||||
color: Colors.white,
|
||||
margin: EdgeInsets.zero,
|
||||
child: /*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.asMap().entries.map((row) {
|
||||
return DataRow(
|
||||
cells: row.value.asMap().entries.map((col) {
|
||||
String colTitle = _headers[col.key];
|
||||
return DataCell(colTitle == "物流名称"
|
||||
? Row(
|
||||
children: [
|
||||
Text("${col.value}"),
|
||||
IconButton(
|
||||
// padding: EdgeInsets.all(2),
|
||||
iconSize: 12,
|
||||
onPressed: () {
|
||||
_logComController.text =
|
||||
_data[row.key][col.key]
|
||||
.toString();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext
|
||||
context) =>
|
||||
AlertDialog(
|
||||
// icon: const Icon(Icons.edit),
|
||||
title: const Text(
|
||||
"填写物流公司"),
|
||||
content: Column(
|
||||
mainAxisSize:
|
||||
MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
decoration:
|
||||
const InputDecoration(
|
||||
labelText:
|
||||
"物流公司"),
|
||||
controller:
|
||||
_logComController,
|
||||
)
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
child: const Text(
|
||||
"取消")),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
String
|
||||
logisticsCom =
|
||||
_logComController
|
||||
.text;
|
||||
if (logisticsCom
|
||||
.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context)
|
||||
.showSnackBar(const SnackBar(
|
||||
content:
|
||||
Text("请输入物流公司")));
|
||||
return;
|
||||
}
|
||||
final data =
|
||||
_data;
|
||||
_data[row.key][
|
||||
col.key] =
|
||||
logisticsCom;
|
||||
setState(() {
|
||||
_data = data;
|
||||
});
|
||||
context.pop();
|
||||
},
|
||||
child: const Text(
|
||||
"确认")),
|
||||
],
|
||||
));
|
||||
},
|
||||
icon: const Icon(Icons.edit))
|
||||
],
|
||||
)
|
||||
: colTitle == "物流信息"
|
||||
child: Scrollbar(
|
||||
controller: scrollController,
|
||||
child: SingleChildScrollView(
|
||||
controller: scrollController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: DataTable(
|
||||
columns: _headers.map((el) {
|
||||
return DataColumn(label: Text(el));
|
||||
}).toList(),
|
||||
rows: _data.asMap().entries.map((row) {
|
||||
return DataRow(
|
||||
cells: row.value.asMap().entries.map((col) {
|
||||
String colTitle = _headers[col.key];
|
||||
return DataCell(colTitle == "物流名称"
|
||||
? Row(
|
||||
children: [
|
||||
_data[row.key][col.key]
|
||||
.toString()
|
||||
.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 120,
|
||||
child: Text(
|
||||
_data[row.key][col.key].toString(),
|
||||
overflow:
|
||||
TextOverflow.ellipsis,
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
String orderNumber =
|
||||
_data[row.key][2]
|
||||
.toString();
|
||||
String orderPayWay =
|
||||
_data[row.key][15]
|
||||
.toString();
|
||||
if (orderPayWay.isEmpty ||
|
||||
orderNumber.isEmpty) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
"该行数据有误")));
|
||||
return;
|
||||
}
|
||||
context.pushNamed("logistics",
|
||||
queryParameters: {
|
||||
"orderNumber":
|
||||
_data[row.key][2]
|
||||
.toString(),
|
||||
"orderPayWay":
|
||||
_data[row.key][15]
|
||||
.toString(),
|
||||
}).then((value) {
|
||||
if (value != null) {
|
||||
var newData = _data;
|
||||
newData[row.key][col.key] =
|
||||
value;
|
||||
setState(() {
|
||||
_data = newData;
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
child: const Text("填写"),
|
||||
)
|
||||
Text("${col.value}"),
|
||||
IconButton(
|
||||
// padding: EdgeInsets.all(2),
|
||||
iconSize: 12,
|
||||
onPressed: () {
|
||||
_logComController.text =
|
||||
_data[row.key][col.key]
|
||||
.toString();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(BuildContext
|
||||
context) =>
|
||||
AlertDialog(
|
||||
// icon: const Icon(Icons.edit),
|
||||
title: const Text(
|
||||
"填写物流公司"),
|
||||
content: Column(
|
||||
mainAxisSize:
|
||||
MainAxisSize
|
||||
.min,
|
||||
children: [
|
||||
TextField(
|
||||
decoration:
|
||||
const InputDecoration(
|
||||
labelText: "物流公司"),
|
||||
controller:
|
||||
_logComController,
|
||||
)
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed:
|
||||
() {
|
||||
context
|
||||
.pop();
|
||||
},
|
||||
child: const Text(
|
||||
"取消")),
|
||||
ElevatedButton(
|
||||
onPressed:
|
||||
() {
|
||||
String
|
||||
logisticsCom =
|
||||
_logComController.text;
|
||||
if (logisticsCom
|
||||
.isEmpty) {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text("请输入物流公司")));
|
||||
return;
|
||||
}
|
||||
final data =
|
||||
_data;
|
||||
_data[row.key][col.key] =
|
||||
logisticsCom;
|
||||
setState(
|
||||
() {
|
||||
_data =
|
||||
data;
|
||||
});
|
||||
context
|
||||
.pop();
|
||||
},
|
||||
child: const Text(
|
||||
"确认")),
|
||||
],
|
||||
));
|
||||
},
|
||||
icon: const Icon(Icons.edit))
|
||||
],
|
||||
)
|
||||
: Text("${col.value}"));
|
||||
}).toList());
|
||||
}).toList(),
|
||||
),
|
||||
)
|
||||
/*)*/
|
||||
,
|
||||
: colTitle == "物流信息"
|
||||
? Row(
|
||||
children: [
|
||||
_data[row.key][col.key]
|
||||
.toString()
|
||||
.isNotEmpty
|
||||
? SizedBox(
|
||||
width: 120,
|
||||
child: Text(
|
||||
_data[row.key]
|
||||
[col.key]
|
||||
.toString(),
|
||||
overflow: TextOverflow
|
||||
.ellipsis,
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
String orderNumber =
|
||||
_data[row.key][2]
|
||||
.toString();
|
||||
String orderPayWay =
|
||||
_data[row.key][15]
|
||||
.toString();
|
||||
if (orderPayWay.isEmpty ||
|
||||
orderNumber.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("该行数据有误"),
|
||||
showCloseIcon: true,
|
||||
));
|
||||
return;
|
||||
}
|
||||
context.pushNamed(
|
||||
"logistics",
|
||||
queryParameters: {
|
||||
"orderNumber":
|
||||
_data[row.key][2]
|
||||
.toString(),
|
||||
"orderPayWay":
|
||||
_data[row.key][15]
|
||||
.toString(),
|
||||
"logistics":
|
||||
_data[row.key][12]
|
||||
.toString()
|
||||
}).then((value) {
|
||||
if (value != null) {
|
||||
var newData = _data;
|
||||
newData[row.key]
|
||||
[col.key] = value;
|
||||
setState(() {
|
||||
_data = newData;
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
child: const Text("填写"),
|
||||
)
|
||||
],
|
||||
)
|
||||
: Text("${col.value}"));
|
||||
}).toList());
|
||||
}).toList(),
|
||||
),
|
||||
)),
|
||||
)
|
||||
],
|
||||
)
|
||||
@ -268,18 +278,34 @@ class _OrderListState extends State<OrderList> {
|
||||
});
|
||||
});
|
||||
var fileBytes = _excel.save();
|
||||
String? directory =
|
||||
await FilePicker.platform.getDirectoryPath(dialogTitle: "选择保存位置");
|
||||
if (directory == null || directory.isEmpty) {
|
||||
String fileName = "导出订单${DateTime.now().millisecondsSinceEpoch}.xlsx";
|
||||
String? outputPath = await FilePicker.platform.saveFile(
|
||||
dialogTitle: "选择保存位置",
|
||||
fileName: fileName,
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ["xlsx", "xls"]);
|
||||
if (outputPath == null || outputPath.isEmpty) {
|
||||
return;
|
||||
}
|
||||
File("$directory\\导出订单${DateTime.now().millisecondsSinceEpoch}.xlsx")
|
||||
File(outputPath)
|
||||
..createSync(recursive: true)
|
||||
..writeAsBytesSync(fileBytes!);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text("导出文件成功"),
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: const Text("导出文件成功"),
|
||||
backgroundColor: Colors.green,
|
||||
action: SnackBarAction(
|
||||
label: "打开文件所在位置",
|
||||
onPressed: () {
|
||||
final Uri fileUrl = Uri(
|
||||
scheme: "file",
|
||||
path: p.dirname(outputPath),
|
||||
);
|
||||
launchUrl(fileUrl, mode: LaunchMode.externalApplication);
|
||||
},
|
||||
backgroundColor: Colors.white,
|
||||
textColor: Colors.green,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user