first commit
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../domain/detection_stabilizer.dart';
|
||||
import '../../theme/tokens.dart';
|
||||
import '../../ui/ui.dart';
|
||||
import '../catalog/sign_detail_page.dart';
|
||||
import '../catalog/sign_glyph.dart';
|
||||
import '../theme/sign_style.dart';
|
||||
|
||||
class SignPanel extends StatelessWidget {
|
||||
const SignPanel({
|
||||
super.key,
|
||||
required this.detections,
|
||||
required this.primary,
|
||||
required this.onSelect,
|
||||
});
|
||||
|
||||
final List<SignDetection> detections;
|
||||
final SignDetection? primary;
|
||||
final ValueChanged<SignDetection> onSelect;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final current = primary;
|
||||
if (current == null) {
|
||||
return const AppText.callout(
|
||||
'Наведите камеру на знак. Рамка появится, когда знак удержится в кадре.',
|
||||
);
|
||||
}
|
||||
final sign = current.sign;
|
||||
final color = categoryColor(sign?.category);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (detections.length > 1)
|
||||
SizedBox(
|
||||
height: 36,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: detections.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final detection = detections[index];
|
||||
final selected = detection.rawLabel == current.rawLabel;
|
||||
return CupertinoButton(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
minimumSize: const Size(44, 32),
|
||||
color: selected
|
||||
? AppColors.of(context, AppColors.accent)
|
||||
: AppColors.of(context, AppColors.systemGray5),
|
||||
borderRadius: BorderRadius.circular(AppRadii.capsule),
|
||||
onPressed: () => onSelect(detection),
|
||||
child: Text(
|
||||
detection.titleCode,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: selected
|
||||
? const Color(0xFFFFFFFF)
|
||||
: AppColors.of(context, AppColors.label),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (detections.length > 1) const SizedBox(height: AppSpacing.s2),
|
||||
Row(
|
||||
children: [
|
||||
AppText.title(current.titleCode, color: color),
|
||||
const SizedBox(width: AppSpacing.s3),
|
||||
AppText.callout('${(current.confidence * 100).round()}%'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.s2),
|
||||
if (sign == null)
|
||||
AppText.body(
|
||||
'Модель назвала «${current.rawLabel}». Такого номера нет в справочнике, поэтому правило не показываю.',
|
||||
)
|
||||
else ...[
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SignGlyph(sign: sign, size: 64),
|
||||
const SizedBox(width: AppSpacing.s3),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppText.headline(sign.name),
|
||||
const SizedBox(height: AppSpacing.s2),
|
||||
AppText.callout(sign.action),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (sign.requiresReadingTheSign) ...[
|
||||
const SizedBox(height: AppSpacing.s2),
|
||||
const AppText.footnote(
|
||||
faceReadingWarning,
|
||||
color: AppColors.systemOrange,
|
||||
),
|
||||
],
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: CupertinoButton(
|
||||
padding: const EdgeInsets.only(top: AppSpacing.s2),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute<void>(
|
||||
builder: (_) => SignDetailPage(sign: sign),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Подробнее'),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DetectionOverlay extends StatelessWidget {
|
||||
const DetectionOverlay({
|
||||
super.key,
|
||||
required this.detections,
|
||||
required this.onSelect,
|
||||
});
|
||||
|
||||
final List<SignDetection> detections;
|
||||
final ValueChanged<SignDetection> onSelect;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = constraints.maxWidth;
|
||||
final height = constraints.maxHeight;
|
||||
return Stack(
|
||||
children: [
|
||||
for (final detection in detections)
|
||||
Positioned(
|
||||
left: detection.box.left * width,
|
||||
top: detection.box.top * height,
|
||||
width: detection.box.width * width,
|
||||
height: detection.box.height * height,
|
||||
child: GestureDetector(
|
||||
onTap: () => onSelect(detection),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: categoryColor(detection.sign?.category),
|
||||
width: 3,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: ColoredBox(
|
||||
color: categoryColor(detection.sign?.category),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
child: Text(
|
||||
detection.titleCode,
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF000000),
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user