feat: 电液控实时计算

This commit is contained in:
louis 2024-04-01 14:27:44 +08:00
parent decf1cd363
commit 27a92960c5
6 changed files with 253 additions and 174 deletions

View File

@ -1,4 +1,8 @@
import 'dart:math';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart'; import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/screens/sale_quotation/components/data_table.dart'; import 'package:sk_base_mobile/screens/sale_quotation/components/data_table.dart';
@ -16,17 +20,38 @@ class SaleQuotationPage extends StatelessWidget {
final headerTitleStyle = TextStyle( final headerTitleStyle = TextStyle(
fontSize: ScreenAdaper.sp(40), fontSize: ScreenAdaper.sp(40),
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: AppTheme.secondPrimaryTextColorWithBg); color: AppTheme.nearlyBlack);
final headerBgcolor = Color.fromARGB(255, 238, 238, 238);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: const SkAppbar(title: '报价计算'), appBar: SkAppbar(
title: '报价计算',
action: [
TextButton(
onPressed: () {},
child: Row(
children: [
Icon(Icons.add, color: AppTheme.white),
Text(
'添加组',
style: TextStyle(
color: AppTheme.white,
fontSize: ScreenAdaper.sp(35),
fontWeight: FontWeight.w600),
)
],
))
],
),
body: Column( body: Column(
children: [ children: [
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: AppTheme.secondPrimaryColorLight, color: headerBgcolor,
border: Border(bottom: BorderSide(color: Colors.grey[200]!))), border: Border(
bottom: BorderSide(
color: AppTheme.nearlyBlack.withOpacity(0.5)))),
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: ScreenAdaper.width(20), left: ScreenAdaper.width(20),
top: ScreenAdaper.height(10), top: ScreenAdaper.height(10),
@ -67,18 +92,20 @@ class SaleQuotationPage extends StatelessWidget {
], ],
)), )),
Expanded( Expanded(
child: CustomScrollView( child: Obx(() => CustomScrollView(
slivers: controller.groups.map((e) => buildBody(e)).toList(), slivers: controller.groups
)), .mapIndexed<Widget>((index, e) => buildBody(e, index))
.toList(),
))),
], ],
), ),
); );
} }
Widget buildBody(SaleQuotationModel group) { Widget buildBody(SaleQuotationModel group, int index) {
final titleStyle = TextStyle( final titleStyle = TextStyle(
fontSize: ScreenAdaper.sp(40), fontSize: ScreenAdaper.sp(40),
color: AppTheme.secondPrimaryTextColorWithBg, color: AppTheme.nearlyBlack,
fontWeight: FontWeight.w600); fontWeight: FontWeight.w600);
final subTextStyle = final subTextStyle =
TextStyle(color: AppTheme.grey, fontSize: ScreenAdaper.sp(30)); TextStyle(color: AppTheme.grey, fontSize: ScreenAdaper.sp(30));
@ -86,39 +113,94 @@ class SaleQuotationPage extends StatelessWidget {
return SliverStickyHeader.builder( return SliverStickyHeader.builder(
builder: (context, state) => Container( builder: (context, state) => Container(
height: ScreenAdaper.height(80), height: ScreenAdaper.height(80),
color: AppTheme.secondPrimaryColorLight color: headerBgcolor.withOpacity(1.0 - state.scrollPercentage),
.withOpacity(1.0 - state.scrollPercentage),
padding: EdgeInsets.symmetric(horizontal: ScreenAdaper.width(20)),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: InkWell(
onTap: () {
controller.groups[index].isExpanded.value =
!controller.groups[index].isExpanded.value;
},
child: Row( child: Row(
children: [ children: [
Obx(() => controller.groups[index].isExpanded.value
? IconButton(
padding: EdgeInsets.zero,
onPressed: () {
controller.groups[index].isExpanded.value = false;
},
icon: const Icon(
Icons.expand_more,
color: AppTheme.nearlyBlack,
),
)
: IconButton(
padding: EdgeInsets.zero,
onPressed: () {
controller.groups[index].isExpanded.value = true;
},
icon: const Icon(
Icons.chevron_right,
color: AppTheme.nearlyBlack,
),
)),
Text( Text(
group.name, group.name,
style: titleStyle, style: titleStyle,
), ),
Spacer(), const Spacer(),
IconButton( IconButton(
onPressed: () { onPressed: () {
ModalUtil.confirm(title: '确定要删除此组吗?', onConfirm: () {}); ModalUtil.confirm(title: '确定要删除此组吗?', onConfirm: () {});
}, },
icon: Icon( icon: const Icon(
// Icons.add_circle_outline,
Icons.remove_circle_outline_outlined, Icons.remove_circle_outline_outlined,
color: AppTheme.secondPrimaryTextColorWithBg, color: AppTheme.nearlyBlack,
))
],
)), )),
sliver: SliverList( IconButton(
onPressed: () {},
icon: const Icon(
Icons.add_circle_outline,
color: AppTheme.nearlyBlack,
)),
],
))),
sliver: Obx(() => !controller.groups[index].isExpanded.value
? SliverList(
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
(context, i) => Container( (context, i) => SizedBox(),
childCount: 0,
))
: SliverList(
delegate: SliverChildBuilderDelegate(
(context, i) => Slidable(
key: UniqueKey(),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const DrawerMotion(),
children: [
SlidableAction(
padding: EdgeInsets.zero,
onPressed: (_) {},
backgroundColor: AppTheme.dangerColor,
foregroundColor: Colors.white,
icon: Icons.delete,
label: 'Delete',
),
],
),
child: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: ScreenAdaper.width(20), left: ScreenAdaper.width(20),
top: ScreenAdaper.height(15), top: ScreenAdaper.height(15),
bottom: ScreenAdaper.height(15)), bottom: ScreenAdaper.height(15),
constraints: BoxConstraints(minHeight: ScreenAdaper.height(80)), ),
constraints:
BoxConstraints(minHeight: ScreenAdaper.height(100)),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
bottom: BorderSide(width: 1, color: Colors.grey[200]!))), bottom: BorderSide(width: 1, color: Colors.grey[200]!),
),
),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
@ -127,14 +209,18 @@ class SaleQuotationPage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row(children: [ Row(
children: [
Expanded( Expanded(
child: Text( child: Text(
'${controller.products[i].name}', '${group.items[i].name}',
style: TextStyle(fontSize: ScreenAdaper.sp(35)), style: TextStyle(
)) fontSize: ScreenAdaper.sp(35)),
]), ),
if (controller.products[i].spec != null) ),
],
),
if (group.items[i].spec != null)
Row( Row(
children: [ children: [
Text( Text(
@ -142,12 +228,12 @@ class SaleQuotationPage extends StatelessWidget {
style: subTextStyle, style: subTextStyle,
), ),
Text( Text(
'${controller.products[i].spec ?? ''}', '${group.items[i].spec ?? ''}',
style: subTextStyle, style: subTextStyle,
) ),
], ],
), ),
if (controller.products[i].unit != null) if (group.items[i].unit != null)
Row( Row(
children: [ children: [
Text( Text(
@ -155,12 +241,12 @@ class SaleQuotationPage extends StatelessWidget {
style: subTextStyle, style: subTextStyle,
), ),
Text( Text(
'${controller.products[i].unit ?? ''}', '${group.items[i].unit ?? ''}',
style: subTextStyle, style: subTextStyle,
) ),
], ],
), ),
if (controller.products[i].remark != null) if (group.items[i].remark != null)
Row( Row(
children: [ children: [
Text( Text(
@ -169,14 +255,16 @@ class SaleQuotationPage extends StatelessWidget {
), ),
Expanded( Expanded(
child: Text( child: Text(
'${controller.products[i].remark ?? ''}${controller.products[i].remark ?? ''}${controller.products[i].remark ?? ''}', '${group.items[i].remark ?? ''}${group.items[i].remark ?? ''}${controller.products[i].remark ?? ''}',
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: subTextStyle, style: subTextStyle,
)) ),
),
], ],
) ),
], ],
)), ),
),
VerticalDivider(), VerticalDivider(),
Container( Container(
alignment: Alignment.center, alignment: Alignment.center,
@ -192,21 +280,25 @@ class SaleQuotationPage extends StatelessWidget {
alignment: Alignment.center, alignment: Alignment.center,
width: amountWidth, width: amountWidth,
child: Text('¥63450000'), child: Text('¥63450000'),
) ),
], ],
), ),
), ),
childCount: controller.products.length,
), ),
childCount: !controller.groups[index].isExpanded.value
? 0
: group.items.length,
), ),
)),
); );
} }
} }
class SaleQuotationModel { class SaleQuotationModel {
final String name; final String name;
List<SaleQuotationItemModel>? items; RxBool isExpanded = true.obs;
SaleQuotationModel({required this.name, this.items}); List<SaleQuotationItemModel> items;
SaleQuotationModel({required this.name, required this.items});
} }
class SaleQuotationItemModel { class SaleQuotationItemModel {
@ -224,7 +316,7 @@ class SaleQuotationItemModel {
class SaleQuotationController extends GetxController { class SaleQuotationController extends GetxController {
static SaleQuotationController get to => Get.find(); static SaleQuotationController get to => Get.find();
List<SaleQuotationItemModel> products = [ RxList<SaleQuotationItemModel> products = RxList([
SaleQuotationItemModel(name: '矿用本安型支架控制器', unit: '', spec: 'ZDYZ-Z'), SaleQuotationItemModel(name: '矿用本安型支架控制器', unit: '', spec: 'ZDYZ-Z'),
SaleQuotationItemModel(name: '矿用本安型电磁阀驱动器'), SaleQuotationItemModel(name: '矿用本安型电磁阀驱动器'),
SaleQuotationItemModel(name: '矿用隔爆兼本安型电源'), SaleQuotationItemModel(name: '矿用隔爆兼本安型电源'),
@ -245,15 +337,21 @@ class SaleQuotationController extends GetxController {
SaleQuotationItemModel(name: '矿用本安型LED信号灯'), SaleQuotationItemModel(name: '矿用本安型LED信号灯'),
SaleQuotationItemModel(name: '倾角传感器'), SaleQuotationItemModel(name: '倾角传感器'),
SaleQuotationItemModel(name: '各类安装附件'), SaleQuotationItemModel(name: '各类安装附件'),
];
RxList<SaleQuotationModel> groups = RxList<SaleQuotationModel>([
SaleQuotationModel(name: '中间过渡架电控部分'),
SaleQuotationModel(name: '端头架电控部分'),
SaleQuotationModel(name: '主阀部分'),
SaleQuotationModel(name: '自动反冲洗过滤器部分'),
SaleQuotationModel(name: '位移测量部分'),
SaleQuotationModel(name: '压力检测部分'),
SaleQuotationModel(name: '煤机定位部分'),
SaleQuotationModel(name: '姿态检测部分'),
]); ]);
RxList<SaleQuotationModel> groups = RxList<SaleQuotationModel>([]);
@override
void onReady() {
groups.assignAll([
SaleQuotationModel(name: '中间过渡架电控部分', items: products),
SaleQuotationModel(name: '端头架电控部分', items: products),
SaleQuotationModel(name: '主阀部分', items: products),
SaleQuotationModel(name: '自动反冲洗过滤器部分', items: products),
SaleQuotationModel(name: '位移测量部分', items: products),
SaleQuotationModel(name: '压力检测部分', items: products),
SaleQuotationModel(name: '煤机定位部分', items: products),
SaleQuotationModel(name: '姿态检测部分', items: products),
]);
super.onReady();
}
} }

View File

@ -18,15 +18,13 @@ class ModalUtil {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(ScreenAdaper.sp(20)), borderRadius: BorderRadius.circular(ScreenAdaper.sp(20)),
), ),
actionsPadding: EdgeInsets.symmetric(), actionsPadding: EdgeInsets.zero,
contentPadding: EdgeInsets.symmetric( titlePadding: EdgeInsets.zero,
horizontal: ScreenAdaper.width(20),
vertical: ScreenAdaper.height(20)),
titlePadding: EdgeInsets.symmetric(),
title: title != null title: title != null
? Container( ? Container(
padding: padding: EdgeInsets.symmetric(
EdgeInsets.symmetric(vertical: ScreenAdaper.height(20)), vertical: ScreenAdaper.height(30),
horizontal: ScreenAdaper.width(30)),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(
bottom: BorderSide( bottom: BorderSide(
@ -36,7 +34,7 @@ class ModalUtil {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon( const Icon(
Icons.error_outline, Icons.error_outline,
color: AppTheme.dangerColor, color: AppTheme.dangerColor,
), ),
@ -52,7 +50,6 @@ class ModalUtil {
]), ]),
) )
: null, : null,
// actionsAlignment: MainAxisAlignment.spaceEvenly,
actions: [ actions: [
Row( Row(
children: [ children: [
@ -72,7 +69,7 @@ class ModalUtil {
color: Colors.black, fontSize: ScreenAdaper.sp(40)), color: Colors.black, fontSize: ScreenAdaper.sp(40)),
)), )),
)), )),
VerticalDivider(), const VerticalDivider(),
Expanded( Expanded(
child: InkWell( child: InkWell(
onTap: () { onTap: () {

View File

@ -2,11 +2,15 @@ import 'package:flutter/material.dart';
class SkAppbar extends StatelessWidget implements PreferredSizeWidget { class SkAppbar extends StatelessWidget implements PreferredSizeWidget {
final String title; final String title;
const SkAppbar({super.key, required this.title}); final List<Widget>? action;
const SkAppbar({super.key, required this.title, this.action});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppBar(title: Text(title)); return AppBar(
title: Text(title),
actions: action,
);
} }
@override @override

View File

@ -366,6 +366,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.9.0" version: "5.9.0"
flutter_slidable:
dependency: "direct main"
description:
name: flutter_slidable
sha256: "673403d2eeef1f9e8483bd6d8d92aae73b1d8bd71f382bc3930f699c731bc27c"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
flutter_staggered_grid_view: flutter_staggered_grid_view:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -64,6 +64,7 @@ dependencies:
flutter_svg: ^2.0.10+1 flutter_svg: ^2.0.10+1
flutter_sticky_header: ^0.6.5 flutter_sticky_header: ^0.6.5
data_table_2: ^2.5.12 data_table_2: ^2.5.12
flutter_slidable: ^3.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter

View File

@ -1,29 +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:sk_base_mobile/index.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const IndexPage());
// 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);
});
}