Home > other >  How to add button in Flutter
How to add button in Flutter

Time:12-28

I am new in flutter. I am following some YouTube videos to learn flutter. After adding a picture in card(home screen) now I want to add two buttons below that picture. how can i do it.

the picture Adding code

body: Center(
        child: Card(
          child: Column(
            children: [Image.asset("assets/image-name")],
          ),
        ),
      ),

CodePudding user response:

Here you have a great page, where you can find implementations of basic material widgets in Flutter.

For your example, it would look like this:

body: Center(
        child: Card(
          child: Column(
            children: [
              Image.asset("assets/image-name"),
              ElevatedButton(
                onPressed: () {
                  // Respond to button press
                },
              child: Text('CONTAINED BUTTON'),
              )
            ],
          ),
        ),
      ),

For a second button, you can just add another one in the children array. You can also wrap both buttons in Row widget, that will allow you to place them horizontally, next to each other.

  • Related