avatar

Posted by Oerror .com

25 Oct, 2024,

Updated at 22 Dec, 2024

Implement a Custom Stateless Button Widget

Create a StatelessWidget called CustomButton in Flutter that takes two parameters: buttonText and onPressed. The button should display the buttonText and trigger the onPressed function when clicked. Style the button with a background color, padding, and rounded corners.

Requirements:

  • The button text should be centered and bold.
  • The widget should not require state management, as it only displays data and triggers a function.
  • The onPressed function should be of type VoidCallback.

Example Code Usage:

dart

Copy code

CustomButton(  buttonText: 'Press Me',  onPressed: () {    print('Button pressed');  }, );

Question 2: Implement a Counter App with StatefulWidget

Description:
Build a StatefulWidget in Flutter named CounterApp that displays a counter value and two buttons: Increment and Decrement. The Increment button should increase the counter value, while the Decrement button should decrease it. Ensure that the counter value updates on the screen as the buttons are pressed.

Requirements:

  • The widget should maintain state, as it needs to update the counter value in real-time.
  • Display the counter value in the center of the screen in large font.
  • Ensure the counter does not go below 0.

Example Code Usage:

dart

Copy code

CounterApp();

These questions focus on understanding the StatelessWidget for displaying static content and StatefulWidget for managing state changes in Flutter.

We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept", you consent to our use of cookies. learn more Accept