-1

I want to create car selling app. I want use car start/stop button on onboarding screen & on tap play car engine start sound? Could you help for creating this widget?

Car start/stop button widget

enter image description here

Creating car start/stop button

1
  • I would use a Column and have one of the widgets depend on a boolean, if the button is clicked return a green widget , if the button is false(not clicked) return a grey button. Commented Feb 14, 2024 at 16:05

1 Answer 1

0

You could do something like:

import 'package:flutter/material.dart';

class CarButton extends StatelessWidget {
  const CarButton({super.key});

  @override
  Widget build(BuildContext context) {
    bool isPressed = false;
    return GestureDetector(
      onTap: () {
        isPressed = !isPressed;
      },
      child: Column(
        children: [
          isPressed
              ? Container(
                  height: 10,
                  width: 30,
                  color: Colors.green,
                )
              : Container(
                  height: 10,
                  width: 30,
                  color: Colors.grey,
                ),
          Text('Start'),
          Text('Stop')
        ],
      ),
    );
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

you may have to make it a stateful widget and use setState in onTap

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.