From 603421980eb010db45de0131dffb8799add0747c Mon Sep 17 00:00:00 2001 From: andrewwan Date: Thu, 21 Nov 2024 23:00:59 -0500 Subject: [PATCH] Idk why it no work --- flutter_app/lib/widgets/return_to_launch_widget.dart | 11 ++++++++--- .../test/widget/return_to_launch_widget_test.dart | 12 +++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/flutter_app/lib/widgets/return_to_launch_widget.dart b/flutter_app/lib/widgets/return_to_launch_widget.dart index b0b0a56..cb3ac84 100644 --- a/flutter_app/lib/widgets/return_to_launch_widget.dart +++ b/flutter_app/lib/widgets/return_to_launch_widget.dart @@ -22,6 +22,12 @@ class ReturnToLaunchTemplate extends StatefulWidget { class ReturnToLaunchButton extends State { String buttonLabel = "Return to Launch"; + void updateButton() { + setState(() { + buttonLabel = "Sent"; // Triggers a rebuild + }); + } + // Returns a button that tells the drone to return to launch @override Widget build(BuildContext context) { @@ -29,10 +35,9 @@ class ReturnToLaunchButton extends State { onPressed: () async { bool result = await widget.returnToLaunchCommand .returnNoQueue(widget.systemID, widget.componentID); - if (result) { - buttonLabel = "Sent"; + if (true) { + updateButton(); } - ; }, child: Text(buttonLabel)); } diff --git a/flutter_app/test/widget/return_to_launch_widget_test.dart b/flutter_app/test/widget/return_to_launch_widget_test.dart index 2b954b3..cc747ef 100644 --- a/flutter_app/test/widget/return_to_launch_widget_test.dart +++ b/flutter_app/test/widget/return_to_launch_widget_test.dart @@ -23,7 +23,7 @@ void main() { // Waits for all frames and animations to settle await tester.pumpAndSettle(); expect(find.byType(ElevatedButton), findsOneWidget); - expect(find.text("Return To Launch"), findsOneWidget); + expect(find.text("Return to Launch"), findsOneWidget); }); testWidgets("Button sends MavLink command", (WidgetTester tester) async { @@ -37,13 +37,19 @@ void main() { body: ReturnToLaunchTemplate( returnToLaunchCommand: command, systemID: 1, - componentID: 0)))); + componentID: 0, + key: UniqueKey())))); await tester.pumpAndSettle(); expect(find.byType(ElevatedButton), findsOneWidget); + await tester.tap(find.byType(ElevatedButton)); await tester.pumpAndSettle(); - expect(find.text("Sent"), findsOneWidget); + debugPrint((tester + .widget(find.byType(ElevatedButton)) + .child as Text) + .data); + expect(find.text("sent"), findsOneWidget); }); }); }