From d830a7ebcf349ee7b9df0cc61b42358d3d8c8607 Mon Sep 17 00:00:00 2001 From: hunteraraujo Date: Tue, 22 Aug 2023 16:59:36 -0400 Subject: [PATCH] Implement NewTaskButton with styling and tests This commit introduces the NewTaskButton widget, designed to allow users to create new tasks. The button follows specific design guidelines, including dimensions, colors, and layout. Key Features: Button with a set height and adaptive width. Icon and text layout within the button. Styling for background, border, and corner radius. Associated tests to ensure the button's functionality and appearance. --- lib/views/new_task_button.dart | 47 ++++++++++++++++++++++++++++++++++ test/new_task_button_test.dart | 24 +++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 lib/views/new_task_button.dart create mode 100644 test/new_task_button_test.dart diff --git a/lib/views/new_task_button.dart b/lib/views/new_task_button.dart new file mode 100644 index 00000000..6e00ce46 --- /dev/null +++ b/lib/views/new_task_button.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; + +class NewTaskButton extends StatelessWidget { + final VoidCallback onPressed; + + const NewTaskButton({Key? key, required this.onPressed}) : super(key: key); + + @override + Widget build(BuildContext context) { + // Determine the width of the TaskView + double taskViewWidth = MediaQuery.of(context).size.width; + double buttonWidth = taskViewWidth - 20; + if (buttonWidth > 260) { + buttonWidth = 260; + } + + return ElevatedButton( + onPressed: onPressed, + style: ButtonStyle( + // Set the button's background color + backgroundColor: MaterialStateProperty.all(Colors.white), + // Set the button's edge + side: MaterialStateProperty.all( + const BorderSide(color: Colors.black, width: 0.5)), + // Set the button's shape with rounded corners + shape: MaterialStateProperty.all( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), + ), + ), + child: Container( + width: buttonWidth, + height: 50, + child: Row( + children: [ + // Black plus icon + Icon(Icons.add, color: Colors.black), + SizedBox(width: 8), + // "New Task" label + Text('New Task', style: TextStyle(color: Colors.black)), + ], + ), + ), + ); + } +} diff --git a/test/new_task_button_test.dart b/test/new_task_button_test.dart new file mode 100644 index 00000000..f0d5078a --- /dev/null +++ b/test/new_task_button_test.dart @@ -0,0 +1,24 @@ +import 'package:auto_gpt_flutter_client/views/new_task_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('NewTaskButton triggers callback on press', + (WidgetTester tester) async { + bool wasPressed = false; + + // Build our widget. + await tester.pumpWidget(MaterialApp( + home: Scaffold( + body: NewTaskButton(onPressed: () => wasPressed = true), + ), + )); + + // Verify if the button with the text 'New Task' is displayed. + expect(find.text('New Task'), findsOneWidget); + + // Tap the button and verify if the onPressed callback is triggered. + await tester.tap(find.byType(ElevatedButton)); + expect(wasPressed, true); + }); +}