Skip to content

Commit 13567fd

Browse files
authored
fix: wrong function id on trunk and hood packages (#48)
* fix: send set body instead of toggle for hood and trunk packages * chore: remove gesture control of turn signals on CarWidget * chore: make trunk and hood joysticks bigger on CarWidget * fix: 'null' initial value instead of empty field on request type and parameter id fields of ButtonOutgoingPackagesInputFieldsWidget * chore: improved interaction with joysticks * chore: v0.15.3+34
1 parent ac5b708 commit 13567fd

File tree

7 files changed

+195
-156
lines changed

7 files changed

+195
-156
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:pixel_app_flutter/domain/data_source/extensions/int.dart';
2+
import 'package:pixel_app_flutter/domain/data_source/models/package_data/wrappers/set_value.dart';
3+
4+
final class SetInt8Body extends SetValueBody {
5+
const SetInt8Body({required this.value});
6+
7+
final int value;
8+
9+
@override
10+
SetValueConverter<SetInt8Body> get bytesConverter =>
11+
const SetInt8BodyConverter();
12+
13+
@override
14+
List<Object?> get props => [value];
15+
}
16+
17+
final class SetInt8BodyConverter extends SetValueConverter<SetInt8Body> {
18+
const SetInt8BodyConverter();
19+
20+
@override
21+
List<int> getBodyBytes(SetInt8Body model) {
22+
return model.value.toBytesInt8;
23+
}
24+
}

lib/domain/data_source/models/package_data/package_data.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export 'implementations/two_uint16_with_status_body.dart';
2525
export 'implementations/uint32_with_status_body.dart';
2626
export 'implementations/motor_gear_and_roll.dart';
2727
export 'implementations/int16_with_status_body.dart';
28+
export 'implementations/set_int8_body.dart';
2829
export 'implementations/set_uint8_body.dart';
2930
export 'implementations/voltage.dart';
3031
export 'implementations/speed.dart';

lib/presentation/screens/general/widgets/car_widget.dart

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ class _CarWidgetState extends State<CarWidget> {
2727

2828
Size carSize = Size.zero;
2929

30-
bool leftDoorOpened = true;
31-
bool rightDoorOpened = false;
32-
bool trunkOpened = false;
33-
bool frontTrunkOpened = true;
34-
35-
AxisDirection? horizontalDragDirection;
36-
3730
IconData _getIcon(bool opened) =>
3831
opened ? PixelIcons.unlocked : PixelIcons.locked;
3932

@@ -73,27 +66,9 @@ class _CarWidgetState extends State<CarWidget> {
7366
if (mounted) setState(() {});
7467
}
7568
},
76-
child: GestureDetector(
77-
behavior: HitTestBehavior.deferToChild,
78-
onHorizontalDragUpdate: (details) {
79-
if (details.delta.dx == 0) return;
80-
81-
horizontalDragDirection = details.delta.dx > 0
82-
? AxisDirection.right
83-
: AxisDirection.left;
84-
},
85-
onHorizontalDragEnd: (details) {
86-
if (horizontalDragDirection == AxisDirection.right) {
87-
context.read<LightsCubit>().toggleRightTurnSignal();
88-
} else if (horizontalDragDirection == AxisDirection.left) {
89-
context.read<LightsCubit>().toggleLeftTurnSignal();
90-
}
91-
horizontalDragDirection = null;
92-
},
93-
child: AspectRatio(
94-
aspectRatio: .3972,
95-
child: SvgPicture.asset(carAssetPath),
96-
),
69+
child: AspectRatio(
70+
aspectRatio: .3972,
71+
child: SvgPicture.asset(carAssetPath),
9772
),
9873
),
9974
),
@@ -182,31 +157,25 @@ class _CarWidgetState extends State<CarWidget> {
182157
),
183158
// Hood
184159
Positioned(
185-
top: carSize.height * .04,
160+
top: carSize.height * .02,
186161
right: 0,
187162
left: 0,
188-
child: Transform.scale(
189-
scale: buttonScaleCoef,
190-
alignment: Alignment.topCenter,
191-
child: const Center(
192-
child: TrunkJoystick.big(
193-
parameterId: DataSourceParameterId.hood(),
194-
),
163+
child: Center(
164+
child: TrunkJoystick.big(
165+
parameterId: const DataSourceParameterId.hood(),
166+
sizeFactor: buttonScaleCoef,
195167
),
196168
),
197169
),
198170
// Trunk
199171
Positioned(
200-
bottom: carSize.height * .04,
172+
bottom: carSize.height * .02,
201173
right: 0,
202174
left: 0,
203-
child: Transform.scale(
204-
scale: buttonScaleCoef,
205-
alignment: Alignment.bottomCenter,
206-
child: const Center(
207-
child: TrunkJoystick.big(
208-
parameterId: DataSourceParameterId.trunk(),
209-
),
175+
child: Center(
176+
child: TrunkJoystick.big(
177+
parameterId: const DataSourceParameterId.trunk(),
178+
sizeFactor: buttonScaleCoef,
210179
),
211180
),
212181
),

lib/presentation/screens/user_defined_buttons/widgets/input_fields/button_outgoing_packages_input_fields_widget.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ class ButtonOutgoingPackagesInputFieldsWidget<
128128
deleteCallback: deleteCallback,
129129
dataIsAutofilled: dataIsAutofilled,
130130
dataInitialValue: object.data.map((e) => e.toString()).join(','),
131-
parameterIdInitialValue: object.parameterId.toString(),
132-
requestTypeInitialValue: object.requestType.toString(),
131+
parameterIdInitialValue: object.parameterId?.toString(),
132+
requestTypeInitialValue: object.requestType?.toString(),
133133
);
134134
},
135135
tileModelBuilder: (index) {

lib/presentation/widgets/common/atoms/one_axis_joystick.dart

Lines changed: 138 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -49,115 +49,155 @@ class OneAxisJoystick extends StatefulWidget {
4949
}
5050

5151
class _OneAxisJoystickState extends State<OneAxisJoystick> {
52+
final thumbKey = GlobalKey();
53+
54+
void onPanUpdate(DragUpdateDetails details) {
55+
final delta = widget.axis.isVertical ? -details.delta.dy : details.delta.dx;
56+
widget.controller.onDragUpdate(delta);
57+
widget.notifier.updateCurrentPosition(delta);
58+
}
59+
60+
void onCancel([Axis? axis]) {
61+
if (axis != null && axis != widget.axis) return;
62+
widget.controller.onDragEnd();
63+
widget.notifier.moveAnimated();
64+
}
65+
66+
void onStart([Axis? axis]) {
67+
if (axis != null && axis != widget.axis) return;
68+
widget.controller.onDragStart();
69+
}
70+
5271
@override
5372
Widget build(BuildContext context) {
5473
final axis = widget.axis;
5574
final isVertical = axis.isVertical;
5675

57-
return SizedBox(
58-
height: isVertical ? widget.mainAxisSize : null,
59-
width: isVertical ? widget.crossAxisSize : widget.mainAxisSize,
60-
child: LayoutBuilder(
61-
builder: (context, constraints) {
62-
widget.notifier.setMaxDistance(widget.mainAxisSize);
63-
return ValueListenableBuilder<OneAxisValue>(
64-
valueListenable: widget.notifier,
65-
builder: (context, value, child) {
66-
final factor = value.factor;
67-
final xAlignment = isVertical ? 0.0 : factor;
68-
final yAlignment = isVertical ? factor : 0.0;
69-
return Stack(
70-
alignment: Alignment(xAlignment, -yAlignment),
71-
children: [
72-
Positioned.fill(
73-
top: isVertical ? widget.arrowIconPadding : 0,
74-
right: isVertical ? 0 : null,
75-
bottom: isVertical ? null : 0,
76-
child: Center(
77-
child: Icon(
78-
isVertical
79-
? Icons.keyboard_arrow_up_rounded
80-
: Icons.keyboard_arrow_left_rounded,
81-
size: widget.iconSize,
82-
color: context.colors.disabled,
76+
return GestureDetector(
77+
onPanDown: (details) {
78+
final tapOffset = details.globalPosition;
79+
final renderBox =
80+
thumbKey.currentContext?.findRenderObject() as RenderBox?;
81+
82+
if (renderBox == null) return;
83+
final size = renderBox.size;
84+
85+
final buttonTopRightOffset = renderBox.localToGlobal(Offset.zero);
86+
final buttonCenter =
87+
buttonTopRightOffset + Offset(size.width / 2, size.height / 2);
88+
89+
final buttonRect = Rect.fromCenter(
90+
center: buttonCenter,
91+
width: widget.thumbSize,
92+
height: widget.thumbSize,
93+
);
94+
95+
final isTapOnButton = buttonRect.contains(tapOffset);
96+
97+
if (isTapOnButton) return;
98+
final offsetDelta = tapOffset - buttonCenter;
99+
final delta = isVertical ? -offsetDelta.dy : offsetDelta.dx;
100+
widget.notifier.updateCurrentPosition(delta);
101+
},
102+
onTapUp: (_) => onCancel(),
103+
onPanStart: (_) => onStart(),
104+
onPanUpdate: onPanUpdate,
105+
onLongPressStart: (_) => onStart(),
106+
onLongPressMoveUpdate: (details) {
107+
final currentPosition = widget.axis.isVertical
108+
? widget.mainAxisSize - widget.notifier.value.currentPosition
109+
: widget.notifier.value.currentPosition;
110+
final delta = widget.axis.isVertical
111+
? currentPosition - details.localPosition.dy
112+
: details.localPosition.dx - currentPosition;
113+
widget.controller.onDragUpdate(delta);
114+
widget.notifier.updateCurrentPosition(delta);
115+
},
116+
onPanEnd: (_) => onCancel(),
117+
onLongPressEnd: (_) => onCancel(),
118+
child: ColoredBox(
119+
color: Colors.transparent,
120+
child: SizedBox(
121+
height: isVertical ? widget.mainAxisSize : null,
122+
width: isVertical ? widget.crossAxisSize : widget.mainAxisSize,
123+
child: LayoutBuilder(
124+
builder: (context, constraints) {
125+
widget.notifier.setMaxDistance(widget.mainAxisSize);
126+
return ValueListenableBuilder<OneAxisValue>(
127+
valueListenable: widget.notifier,
128+
builder: (context, value, child) {
129+
final factor = value.factor;
130+
final xAlignment = isVertical ? 0.0 : factor;
131+
final yAlignment = isVertical ? factor : 0.0;
132+
return Stack(
133+
alignment: Alignment(xAlignment, -yAlignment),
134+
children: [
135+
Positioned.fill(
136+
top: isVertical ? widget.arrowIconPadding : 0,
137+
right: isVertical ? 0 : null,
138+
bottom: isVertical ? null : 0,
139+
child: Center(
140+
child: Icon(
141+
isVertical
142+
? Icons.keyboard_arrow_up_rounded
143+
: Icons.keyboard_arrow_left_rounded,
144+
size: widget.iconSize,
145+
color: context.colors.disabled,
146+
),
147+
),
83148
),
84-
),
85-
),
86-
Positioned.fill(
87-
bottom: isVertical ? widget.arrowIconPadding : 0,
88-
left: isVertical ? 0 : null,
89-
top: isVertical ? null : 0,
90-
child: Center(
91-
child: Icon(
92-
isVertical
93-
? Icons.keyboard_arrow_down_rounded
94-
: Icons.keyboard_arrow_right_rounded,
95-
size: widget.iconSize,
96-
color: context.colors.disabled,
149+
Positioned.fill(
150+
bottom: isVertical ? widget.arrowIconPadding : 0,
151+
left: isVertical ? 0 : null,
152+
top: isVertical ? null : 0,
153+
child: Center(
154+
child: Icon(
155+
isVertical
156+
? Icons.keyboard_arrow_down_rounded
157+
: Icons.keyboard_arrow_right_rounded,
158+
size: widget.iconSize,
159+
color: context.colors.disabled,
160+
),
161+
),
162+
),
163+
child ?? const SizedBox.shrink(),
164+
],
165+
);
166+
},
167+
child: GestureDetector(
168+
key: thumbKey,
169+
onVerticalDragStart: (_) => onStart(Axis.vertical),
170+
onVerticalDragUpdate: onPanUpdate,
171+
onVerticalDragEnd: (_) => onCancel(Axis.vertical),
172+
onHorizontalDragStart: (_) => onStart(Axis.horizontal),
173+
onHorizontalDragUpdate: onPanUpdate,
174+
onHorizontalDragEnd: (_) => onCancel(Axis.horizontal),
175+
onTap: widget.controller.onTap,
176+
child: SizedBox.square(
177+
dimension: widget.thumbSize,
178+
child: ColoredBox(
179+
color: Colors.transparent,
180+
child: DecoratedBox(
181+
decoration: BoxDecoration(
182+
shape: BoxShape.circle,
183+
color: context.colors.disabled,
184+
border: Border.all(color: Colors.black26),
185+
boxShadow: const [
186+
BoxShadow(
187+
color: Colors.black12,
188+
blurRadius: 3,
189+
spreadRadius: 3,
190+
),
191+
],
192+
),
97193
),
98194
),
99195
),
100-
child ?? const SizedBox.shrink(),
101-
],
196+
),
102197
);
103198
},
104-
child: GestureDetector(
105-
onVerticalDragStart: !isVertical
106-
? null
107-
: (details) {
108-
widget.controller.onDragStart();
109-
},
110-
onVerticalDragUpdate: !isVertical
111-
? null
112-
: (details) {
113-
widget.notifier.updateCurrentPosition(-details.delta.dy);
114-
},
115-
onVerticalDragEnd: !isVertical
116-
? null
117-
: (details) {
118-
widget.controller.onDragEnd();
119-
widget.notifier.moveAnimated();
120-
},
121-
onHorizontalDragStart: isVertical
122-
? null
123-
: (details) {
124-
widget.controller.onDragStart();
125-
},
126-
onHorizontalDragUpdate: isVertical
127-
? null
128-
: (details) {
129-
final delta =
130-
isVertical ? details.delta.dy : details.delta.dx;
131-
widget.controller.onDragUpdate(delta);
132-
widget.notifier.updateCurrentPosition(delta);
133-
},
134-
onHorizontalDragEnd: isVertical
135-
? null
136-
: (details) {
137-
widget.controller.onDragEnd();
138-
widget.notifier.moveAnimated();
139-
},
140-
onTap: widget.controller.onTap,
141-
child: SizedBox.square(
142-
dimension: widget.thumbSize,
143-
child: DecoratedBox(
144-
decoration: BoxDecoration(
145-
shape: BoxShape.circle,
146-
color: context.colors.disabled,
147-
border: Border.all(color: Colors.black26),
148-
boxShadow: const [
149-
BoxShadow(
150-
color: Colors.black12,
151-
blurRadius: 3,
152-
spreadRadius: 3,
153-
),
154-
],
155-
),
156-
),
157-
),
158-
),
159-
);
160-
},
199+
),
200+
),
161201
),
162202
);
163203
}

0 commit comments

Comments
 (0)