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

42
lib/logistics.dart Normal file
View File

@ -0,0 +1,42 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Logistics extends StatefulWidget {
const Logistics({super.key});
@override
State<Logistics> createState() => _LogisticsState();
}
class _LogisticsState extends State<Logistics> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("填写物流信息"),
),
body: Container(
padding: const EdgeInsets.all(40),
width: double.infinity,
child: Card(
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(),
borderRadius: const BorderRadius.all(Radius.circular(8))),
child: SizedBox(
height: 50,
width: 120,
),
)
],
),
),
),
));
}
}

View File

@ -1,17 +1,29 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:logistics_tools/logistics.dart';
import 'package:logistics_tools/order_list.dart'; import 'package:logistics_tools/order_list.dart';
void main() { void main() {
runApp(const MyApp()); runApp(MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); MyApp({super.key});
final _router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => const OrderList(),
),
GoRoute(path: '/logistics', builder: (context, state) => const Logistics())
],
);
// This widget is the root of your application. // This widget is the root of your application.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp.router(
title: 'Flutter Demo', title: 'Flutter Demo',
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: ThemeData( theme: ThemeData(
@ -33,7 +45,8 @@ class MyApp extends StatelessWidget {
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent), colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent),
useMaterial3: true, useMaterial3: true,
), ),
home: const OrderList(), // home: const OrderList(),
routerConfig: _router,
); );
} }
} }

View File

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

View File

@ -152,6 +152,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
go_router:
dependency: "direct main"
description:
name: go_router
sha256: cdae1b9c8bd7efadcef6112e81c903662ef2ce105cbd220a04bbb7c3425b5554
url: "https://pub.dev"
source: hosted
version: "14.2.0"
js: js:
dependency: transitive dependency: transitive
description: description:
@ -192,6 +200,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.0" version: "3.0.0"
logging:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:

View File

@ -37,6 +37,7 @@ dependencies:
cupertino_icons: ^1.0.6 cupertino_icons: ^1.0.6
excel: ^4.0.3 excel: ^4.0.3
file_picker: ^8.0.5 file_picker: ^8.0.5
go_router: ^14.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View File

@ -13,7 +13,7 @@ import 'package:logistics_tools/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp()); await tester.pumpWidget(MyApp());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);