Ready-to-Fly-Gate (Doku 2.2/4.5): AppModeCubit.toFly() erzwang bisher
Upload + verifiziert + disarmed und warf sonst einen StateError - da
MissionSyncService/Upload-Flow noch nicht angebunden sind, war das Gate
dauerhaft geschlossen und der Fly-Modus damit von der UI aus gar nicht
erreichbar. toFly() wechselt jetzt unbedingt in den Fly-Modus; die
readyToFly-Logik bleibt als Getter erhalten fuer den spaeteren Upload-
Flow. Der eigentliche Schutz vor einem Missions-Upload im armed-Zustand
lebt unveraendert auf Transport-Ebene (MockFlightControllerLink.
uploadMission() wirft dort weiterhin bei armed).
Fly-Modus-Kopfzeile (Doku 3.11/7.2, HTML-Demonstrator: #flightModePill/
#flightModeDropdown): top_mode_bar.dart zeigte im Fly-Modus bisher nur
eine leere Spacer-Flaeche. Zeigt jetzt die Wind-Pille (weiterhin
relevant, Doku 7.2) und eine neue Flugmodus-Auswahl:
- ui/providers/flight_mode_provider.dart: haelt den lokal gewaehlten
FlightMode (Doku 3.1: missionRun/guidedPoint/returnHome/hold), noch
ohne echte FlightControllerLink-Anbindung (Doku 4.19). reset() setzt
auf missionRun (Waypoint) zurueck.
- ui/widgets/flight_mode_pill.dart: PopupMenuButton-Pille "Mode: X" mit
den vier Optionen Waypoint/Point and Fly/Return to Home/Manual (1:1
aus dem HTML-Demonstrator uebernommene Labels).
- top_mode_bar.dart: Fly-Button setzt beim Eintritt in den Fly-Modus
den Flugmodus zurueck auf Waypoint (Doku 3.11: "Standard-
Rueckstellung ... beim Eintritt in Fly-Modus").
Layout-Bug beim Implementieren gefunden und behoben: Expanded(child:
Center(child: FlightModePill())) liess die Kopfzeile ueber den
gesamten Bildschirm expandieren (derselbe "Center/Align ohne Faktor
expandiert auf verfuegbare Constraints"-Fehler wie zuvor schon bei der
Bottom-Stats-Bar in dieser Session) - behoben durch Entfernen des
ueberfluessigen Center-Wrappers, da FlightModePill sein Zentrieren
bereits selbst per Container-alignment uebernimmt. Zusaetzlich einen
RenderFlex-Overflow bei langen Modusnamen ("Return to Home") behoben,
indem der Label-Text in Flexible mit TextOverflow.ellipsis gewrappt
wurde.
Getestet: 2 neue Widget-Tests (Fly-Button wechselt jetzt direkt in den
Fly-Modus statt eine Gate-Snackbar zu zeigen; Flugmodus-Dropdown
wechselt den Modus und setzt ihn beim erneuten Eintritt zurueck),
bestehender Gate-Test ersetzt, ein bestehender Test vereinfacht (die
Gate-Erfuellung vor toFly() ist nicht mehr noetig). Alle 118 Tests
sowie flutter analyze bestehen. Manuell auf dem Pixel_10a-Emulator
verifiziert: Fly-Button wechselt direkt um, Dropdown zeigt alle vier
Optionen, Auswahl uebernimmt das Label korrekt (auch bei langen Namen
ohne Overflow), Rueckstellung auf Waypoint bei erneutem Eintritt
funktioniert.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
153 lines
5.4 KiB
Dart
153 lines
5.4 KiB
Dart
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../app_mode/app_mode_cubit.dart';
|
|
import '../dmc_colors.dart';
|
|
import '../providers/flight_mode_provider.dart';
|
|
import 'flight_mode_pill.dart';
|
|
import 'header_wind_pill.dart';
|
|
import 'map_search_controls.dart';
|
|
|
|
/// Persistente Kopfleiste zum Umschalten zwischen Plan- und Fly-Modus
|
|
/// (HTML-Demonstrator: #topBarWrap/#editModeBtn/#flyModeBtn). Die Leiste
|
|
/// faerbt sich in der Farbe des aktiven Modus; der jeweils andere Modus wird
|
|
/// als solider Button am Rand angeboten, um in ihn zu wechseln.
|
|
///
|
|
/// Traegt ausserhalb des Fly-Modus zusaetzlich die Wind-Pille, Ortssuche und
|
|
/// die Home-/Fit-Buttons in derselben Pille (HTML-Demonstrator: #headerWindPill/
|
|
/// #searchWrap/#homeBtn/#fitBtn sitzen alle in #topBarMiddle, nicht in einer
|
|
/// separaten Leiste) - dafuer lebt der MapController im mapControllerProvider
|
|
/// statt als PlanScreen-privates Feld, siehe dort.
|
|
///
|
|
/// Im Fly-Modus traegt sie stattdessen die Wind-Pille (Doku 7.2: "Wind-
|
|
/// Anzeige nach Hoehe interpoliert") und die Flugmodus-Auswahl (Doku 3.11,
|
|
/// HTML-Demonstrator: #flightModePill) - Ortssuche/Home/Fit sind dort
|
|
/// nicht relevant, da im Fly-Modus keine Missionsbearbeitung stattfindet.
|
|
class TopModeBar extends ConsumerWidget {
|
|
const TopModeBar({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final isFly = context.select((AppModeCubit c) => c.state.mode == AppMode.fly);
|
|
final activeTint = isFly ? DmcColors.flyModeRed : DmcColors.editModeGreen;
|
|
|
|
// Kein SafeArea: das wendet links/rechts die jeweils tatsaechlichen
|
|
// (oft asymmetrischen) Insets an, wodurch die Leiste sichtbar von der
|
|
// Bildschirmmitte abweicht, sobald eine Seite einen groesseren
|
|
// Aussparungsbereich meldet als die andere. Stattdessen derselbe
|
|
// symmetrische Randabstand wie bei den Drehraedern (PlanScreen:
|
|
// safeEdgeInset) - dadurch bleibt die per FractionallySizedBox
|
|
// zentrierte Leiste auch bei asymmetrischen Insets echt mittig.
|
|
final topInset = MediaQuery.of(context).padding.top;
|
|
final safeEdgeInset = math.max(
|
|
MediaQuery.of(context).padding.left,
|
|
MediaQuery.of(context).padding.right,
|
|
);
|
|
|
|
return Padding(
|
|
padding: EdgeInsets.only(
|
|
top: topInset,
|
|
left: safeEdgeInset,
|
|
right: safeEdgeInset,
|
|
),
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.70,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
decoration: BoxDecoration(
|
|
color: activeTint.withValues(alpha: 0.55),
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(26),
|
|
bottomRight: Radius.circular(26),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
_ModeButton(
|
|
label: 'Plan',
|
|
isActive: !isFly,
|
|
inactiveColor: DmcColors.editModeGreen,
|
|
cornerRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(26),
|
|
),
|
|
onTap: () => context.read<AppModeCubit>().toPlan(),
|
|
),
|
|
if (isFly) ...[
|
|
const SizedBox(width: 8),
|
|
const HeaderWindPill(),
|
|
const SizedBox(width: 8),
|
|
const Expanded(child: FlightModePill()),
|
|
const SizedBox(width: 8),
|
|
] else ...[
|
|
const SizedBox(width: 8),
|
|
const HeaderWindPill(),
|
|
const SizedBox(width: 8),
|
|
const Expanded(child: MapSearchControls()),
|
|
const SizedBox(width: 12),
|
|
],
|
|
_ModeButton(
|
|
label: 'Fly',
|
|
isActive: isFly,
|
|
inactiveColor: DmcColors.flyModeRed,
|
|
cornerRadius: const BorderRadius.only(
|
|
bottomRight: Radius.circular(26),
|
|
),
|
|
onTap: () {
|
|
context.read<AppModeCubit>().toFly();
|
|
// Eintritt in den Fly-Modus setzt immer auf Waypoint
|
|
// zurueck (Doku 3.11).
|
|
ref.read(flightModeProvider.notifier).reset();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ModeButton extends StatelessWidget {
|
|
const _ModeButton({
|
|
required this.label,
|
|
required this.isActive,
|
|
required this.inactiveColor,
|
|
required this.cornerRadius,
|
|
required this.onTap,
|
|
});
|
|
|
|
final String label;
|
|
final bool isActive;
|
|
final Color inactiveColor;
|
|
final BorderRadius cornerRadius;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: isActive ? null : onTap,
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 24,
|
|
vertical: isActive ? 6 : 11,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: isActive ? null : inactiveColor.withValues(alpha: 0.85),
|
|
borderRadius: isActive ? null : cornerRadius,
|
|
),
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w800,
|
|
color: Color(0xFF141414),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|