UI 初体验
This commit is contained in:
120
lib/main.dart
120
lib/main.dart
@@ -1,15 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_carbon/flutter_carbon.dart';
|
import 'package:flutter_carbon/flutter_carbon.dart';
|
||||||
|
import 'package:report_manage/pages/import.dart';
|
||||||
|
|
||||||
import 'container.dart';
|
import 'container.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 GlobalKey<NavigatorState> _navKey = GlobalKey();
|
||||||
// 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) {
|
||||||
@@ -19,96 +20,31 @@ class MyApp extends StatelessWidget {
|
|||||||
home: CarbonUIShell(
|
home: CarbonUIShell(
|
||||||
appName: "报表管理",
|
appName: "报表管理",
|
||||||
sideNavItems: [
|
sideNavItems: [
|
||||||
CarbonNavItem(label: "数据导入",),
|
CarbonNavItem(
|
||||||
CarbonNavItem(label: "销售明细",),
|
label: "数据导入",
|
||||||
|
icon: CarbonIcons.upload,
|
||||||
|
onTap: () {
|
||||||
|
_navKey.currentState?.pushReplacement(
|
||||||
|
MaterialPageRoute(builder: (_) => ImportPage()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
CarbonNavItem(
|
||||||
|
label: "销售明细",
|
||||||
|
icon: CarbonIcons.table,
|
||||||
|
onTap: () {
|
||||||
|
_navKey.currentState?.pushReplacement(
|
||||||
|
MaterialPageRoute(builder: (_) => ZContainer()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: ZContainer()
|
child: Navigator(
|
||||||
),
|
key: _navKey,
|
||||||
);
|
onGenerateRoute: (setting) {
|
||||||
}
|
return MaterialPageRoute(builder: (_) => ImportPage());
|
||||||
}
|
},
|
||||||
|
),
|
||||||
class MyHomePage extends StatefulWidget {
|
|
||||||
const MyHomePage({super.key, required this.title});
|
|
||||||
|
|
||||||
// This widget is the home page of your application. It is stateful, meaning
|
|
||||||
// that it has a State object (defined below) that contains fields that affect
|
|
||||||
// how it looks.
|
|
||||||
|
|
||||||
// This class is the configuration for the state. It holds the values (in this
|
|
||||||
// case the title) provided by the parent (in this case the App widget) and
|
|
||||||
// used by the build method of the State. Fields in a Widget subclass are
|
|
||||||
// always marked "final".
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
|
||||||
int _counter = 0;
|
|
||||||
|
|
||||||
void _incrementCounter() {
|
|
||||||
setState(() {
|
|
||||||
// This call to setState tells the Flutter framework that something has
|
|
||||||
// changed in this State, which causes it to rerun the build method below
|
|
||||||
// so that the display can reflect the updated values. If we changed
|
|
||||||
// _counter without calling setState(), then the build method would not be
|
|
||||||
// called again, and so nothing would appear to happen.
|
|
||||||
_counter++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
// This method is rerun every time setState is called, for instance as done
|
|
||||||
// by the _incrementCounter method above.
|
|
||||||
//
|
|
||||||
// The Flutter framework has been optimized to make rerunning build methods
|
|
||||||
// fast, so that you can just rebuild anything that needs updating rather
|
|
||||||
// than having to individually change instances of widgets.
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
// TRY THIS: Try changing the color here to a specific color (to
|
|
||||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
|
||||||
// change color while the other colors stay the same.
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
||||||
// Here we take the value from the MyHomePage object that was created by
|
|
||||||
// the App.build method, and use it to set our appbar title.
|
|
||||||
title: Text(widget.title),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
// Center is a layout widget. It takes a single child and positions it
|
|
||||||
// in the middle of the parent.
|
|
||||||
child: Column(
|
|
||||||
// Column is also a layout widget. It takes a list of children and
|
|
||||||
// arranges them vertically. By default, it sizes itself to fit its
|
|
||||||
// children horizontally, and tries to be as tall as its parent.
|
|
||||||
//
|
|
||||||
// Column has various properties to control how it sizes itself and
|
|
||||||
// how it positions its children. Here we use mainAxisAlignment to
|
|
||||||
// center the children vertically; the main axis here is the vertical
|
|
||||||
// axis because Columns are vertical (the cross axis would be
|
|
||||||
// horizontal).
|
|
||||||
//
|
|
||||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
|
||||||
// action in the IDE, or press "p" in the console), to see the
|
|
||||||
// wireframe for each widget.
|
|
||||||
mainAxisAlignment: .center,
|
|
||||||
children: [
|
|
||||||
const Text('You have pushed the button this many times:'),
|
|
||||||
Text(
|
|
||||||
'$_counter',
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _incrementCounter,
|
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:drift_flutter/drift_flutter.dart';
|
||||||
|
|
||||||
|
part 'models.g.dart';
|
||||||
|
|
||||||
/// 导入记录表定义
|
/// 导入记录表定义
|
||||||
class ImportRecord extends Table {
|
class ImportRecord extends Table {
|
||||||
@@ -24,5 +27,46 @@ class SaleDetail extends Table {
|
|||||||
TextColumn get objName => text()();
|
TextColumn get objName => text()();
|
||||||
|
|
||||||
/// 进销单据性质
|
/// 进销单据性质
|
||||||
|
TextColumn get type => text().map(const SaleDetailTypeConverter())();
|
||||||
|
|
||||||
/// 关联导入记录 ID
|
/// 关联导入记录 ID
|
||||||
|
IntColumn get importId => integer().references(ImportRecord, #id)();
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SaleDetailType {
|
||||||
|
bill('挂账', 'BILL', ['挂账']),
|
||||||
|
cash('现金', 'CASH', ['挂账']),
|
||||||
|
online('线上支付', 'ONLINE', ['挂账']);
|
||||||
|
|
||||||
|
final String desc;
|
||||||
|
final String code;
|
||||||
|
final List<String> identity;
|
||||||
|
static final Map<String, SaleDetailType> map = {
|
||||||
|
for (var type in SaleDetailType.values) type.code: type,
|
||||||
|
};
|
||||||
|
const SaleDetailType(this.desc, this.code, this.identity);
|
||||||
|
static SaleDetailType? of(String param) => map[param];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SaleDetailTypeConverter extends TypeConverter<SaleDetailType, String> {
|
||||||
|
const SaleDetailTypeConverter();
|
||||||
|
|
||||||
|
@override
|
||||||
|
SaleDetailType fromSql(String code) => SaleDetailType.of(code)!;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toSql(SaleDetailType type) => type.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加数据库类
|
||||||
|
@DriftDatabase(tables: [ImportRecord, SaleDetail])
|
||||||
|
class AppDatabase extends _$AppDatabase {
|
||||||
|
AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection());
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get schemaVersion => 1;
|
||||||
|
|
||||||
|
static QueryExecutor _openConnection() {
|
||||||
|
return driftDatabase(name: 'my_database');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
49
lib/pages/import.dart
Normal file
49
lib/pages/import.dart
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_carbon/flutter_carbon.dart';
|
||||||
|
|
||||||
|
class ImportPage extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
State<ImportPage> createState() => ImportState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ImportState extends State<ImportPage> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: .all(24),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: .end,
|
||||||
|
children: [
|
||||||
|
CarbonButton(child: Text('导入数据'), onPressed: () => print("点击按钮")),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
CarbonDataTable(
|
||||||
|
headers: [
|
||||||
|
CarbonDataTableHeader(key: 'time', label: '导入时间'),
|
||||||
|
CarbonDataTableHeader(key: 'fileName', label: '文件名称'),
|
||||||
|
CarbonDataTableHeader(key: 'remark', label: '导入备注'),
|
||||||
|
],
|
||||||
|
rows: [
|
||||||
|
CarbonDataTableRow(
|
||||||
|
cells: [
|
||||||
|
CarbonDataTableCell(child: Text("2025-05-21")),
|
||||||
|
CarbonDataTableCell(child: Text("进货单.xlsx")),
|
||||||
|
CarbonDataTableCell(child: Text("总之这就是备注啦")),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
CarbonDataTableRow(
|
||||||
|
cells: [
|
||||||
|
CarbonDataTableCell(child: Text("2025-05-26")),
|
||||||
|
CarbonDataTableCell(child: Text("销售单.xlsx")),
|
||||||
|
CarbonDataTableCell(child: Text("二次备注")),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
// This is a basic Flutter widget test.
|
|
||||||
//
|
|
||||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
||||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
|
||||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
|
||||||
// tree, read text, and verify that the values of widget properties are correct.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:report_manage/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
|
||||||
// Build our app and trigger a frame.
|
|
||||||
await tester.pumpWidget(const MyApp());
|
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
|
||||||
expect(find.text('0'), findsOneWidget);
|
|
||||||
expect(find.text('1'), findsNothing);
|
|
||||||
|
|
||||||
// Tap the '+' icon and trigger a frame.
|
|
||||||
await tester.tap(find.byIcon(Icons.add));
|
|
||||||
await tester.pump();
|
|
||||||
|
|
||||||
// Verify that our counter has incremented.
|
|
||||||
expect(find.text('0'), findsNothing);
|
|
||||||
expect(find.text('1'), findsOneWidget);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user