From 62a7c7f29e5196bcfe02c96270e3861a304a692d Mon Sep 17 00:00:00 2001 From: quantulr <35954003+quantulr@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:22:52 +0800 Subject: [PATCH] init --- lib/logistics.dart | 42 +++++++++++++ lib/main.dart | 21 +++++-- lib/order_list.dart | 135 ++++++++++++++++++++++++++---------------- pubspec.lock | 16 +++++ pubspec.yaml | 1 + test/widget_test.dart | 2 +- 6 files changed, 160 insertions(+), 57 deletions(-) create mode 100644 lib/logistics.dart diff --git a/lib/logistics.dart b/lib/logistics.dart new file mode 100644 index 0000000..d798e78 --- /dev/null +++ b/lib/logistics.dart @@ -0,0 +1,42 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class Logistics extends StatefulWidget { + const Logistics({super.key}); + + @override + State createState() => _LogisticsState(); +} + +class _LogisticsState extends State { + @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, + ), + ) + ], + ), + ), + ), + )); + } +} diff --git a/lib/main.dart b/lib/main.dart index 0c9b361..b863c68 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,17 +1,29 @@ 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'; void main() { - runApp(const MyApp()); + runApp(MyApp()); } 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. @override Widget build(BuildContext context) { - return MaterialApp( + return MaterialApp.router( title: 'Flutter Demo', debugShowCheckedModeBanner: false, theme: ThemeData( @@ -33,7 +45,8 @@ class MyApp extends StatelessWidget { colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent), useMaterial3: true, ), - home: const OrderList(), + // home: const OrderList(), + routerConfig: _router, ); } } diff --git a/lib/order_list.dart b/lib/order_list.dart index 1e09044..726c6a6 100644 --- a/lib/order_list.dart +++ b/lib/order_list.dart @@ -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 { final List lst = []; List headers = []; + List> data = []; + ScrollController scrollController = ScrollController(); @override @@ -43,57 +45,78 @@ class _OrderListState extends State { 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 { return el?.value.toString() ?? ""; }).toList() ?? []; + List> _data = + excel.tables[tableKey]?.rows.sublist(1).map((row) { + return row.map((col) { + return col?.value ?? ""; + }).toList(); + }).toList() ?? + []; setState(() { headers = _headers; + data = _data; }); } else { // 取消选择 diff --git a/pubspec.lock b/pubspec.lock index 62bcae5..339e631 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -152,6 +152,14 @@ packages: description: flutter source: sdk 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: dependency: transitive description: @@ -192,6 +200,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ec424aa..a22e497 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: cupertino_icons: ^1.0.6 excel: ^4.0.3 file_picker: ^8.0.5 + go_router: ^14.2.0 dev_dependencies: flutter_test: diff --git a/test/widget_test.dart b/test/widget_test.dart index 8e381c9..2b9ee04 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:logistics_tools/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget);