How to make a Widget change color briefly like a button

z4rtx

So, Buttons behave in a way that will make the user know that he/she clicked the button[The button changes its foreground color briefly when clicked.]

Now my questions is how do i do it on a container in the way that when user clicks the widget, it becomes responsive[foreground darkens], and when user lifts finger from the widget[becomes normal]?

my Code for the Widget is below:

     Container(
                height: 60,
                width: double.infinity,
                margin: EdgeInsets.all(10.0),
                child: Material(
                  borderRadius: BorderRadius.circular(10.0),
                  elevation: 1,
                  shadowColor: Colors.black,
                  child: Padding(
                    padding: EdgeInsets.only(left: 8),
                    child: Stack(
                      children: <Widget>[
                        Align(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            'Click Me',
                            style: TextStyle(
                              fontFamily: 'Poppins',
                              fontSize: 14,
                            ),
                          ),
                        ),
                        Align(
                          alignment: Alignment.centerRight,
                          child: Icon(
                            CupertinoIcons.right_chevron,
                            color: color_primary,
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              )
Thepeanut

Add an InkWell with a non-null onTap parameter around your Padding widget.

Container(
          height: 60,
          width: double.infinity,
          margin: EdgeInsets.all(10.0),
          child: Material(
            borderRadius: BorderRadius.circular(10.0),
            elevation: 1,
            shadowColor: Colors.black,
            child: InkWell(
              borderRadius: BorderRadius.circular(10.0),
              onTap: () {
                // do something on tap
              },
              child: Padding(
                padding: EdgeInsets.only(left: 8),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Expanded(
                      child: Text(
                        'Click Me',
                        style: TextStyle(
                          fontFamily: 'Poppins',
                          fontSize: 14,
                        ),
                      ),
                    ),
                    SizedBox(width: 10.0),
                    Icon(
                      CupertinoIcons.right_chevron,
                      color: Theme.of(context).primaryColor,
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),

Also please take a look at a way you can achieve the same result without using a Stack (since it might be an overhead for this situation).

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to change button color

분류에서Dev

How to change the color of button and pause screen for few second when it clicked?

분류에서Dev

Change button color when clicked

분류에서Dev

jfxtras - CalendarPicker change button color

분류에서Dev

How to create a customize android tab widget, that the selected tab will change its default color background?

분류에서Dev

Trying to get a Button to change a Text widget

분류에서Dev

How to make a result like this?

분류에서Dev

Facebook iOS SDK - How can I make a Page Like Button works?

분류에서Dev

Change foreground color of back button in UWP NavigationView

분류에서Dev

XPages - change background color of place bar button

분류에서Dev

How to change button value?

분류에서Dev

I want to change the color of a button for a few seconds than change it back

분류에서Dev

How to change the color of *just* the header?

분류에서Dev

How to change color of image in JavaFX

분류에서Dev

How to change color of CCDrawNode component?

분류에서Dev

how to make button in ionic + css

분류에서Dev

How do I change Button Text color onclick event(asp.net, C#)using Css file?

분류에서Dev

How to change the Dash button icon?

분류에서Dev

Change color of an asp.net button on mouse hover using css

분류에서Dev

How to avoid color changes when button is disabled?

분류에서Dev

How to bind to Button's foreground color?

분류에서Dev

How to make html layout like my image?

분류에서Dev

how to make showcase solid background color

분류에서Dev

How can I remove onEvent from button widget in Corona?

분류에서Dev

How to dynamically change SVG fill color?

분류에서Dev

How to change default selection color of a ListView?

분류에서Dev

How to change the color of the text of a label in Xcode

분류에서Dev

How to change a font/background color in transparent windows?

분류에서Dev

How to find and change color of specific word in string

Related 관련 기사

  1. 1

    How to change button color

  2. 2

    How to change the color of button and pause screen for few second when it clicked?

  3. 3

    Change button color when clicked

  4. 4

    jfxtras - CalendarPicker change button color

  5. 5

    How to create a customize android tab widget, that the selected tab will change its default color background?

  6. 6

    Trying to get a Button to change a Text widget

  7. 7

    How to make a result like this?

  8. 8

    Facebook iOS SDK - How can I make a Page Like Button works?

  9. 9

    Change foreground color of back button in UWP NavigationView

  10. 10

    XPages - change background color of place bar button

  11. 11

    How to change button value?

  12. 12

    I want to change the color of a button for a few seconds than change it back

  13. 13

    How to change the color of *just* the header?

  14. 14

    How to change color of image in JavaFX

  15. 15

    How to change color of CCDrawNode component?

  16. 16

    how to make button in ionic + css

  17. 17

    How do I change Button Text color onclick event(asp.net, C#)using Css file?

  18. 18

    How to change the Dash button icon?

  19. 19

    Change color of an asp.net button on mouse hover using css

  20. 20

    How to avoid color changes when button is disabled?

  21. 21

    How to bind to Button's foreground color?

  22. 22

    How to make html layout like my image?

  23. 23

    how to make showcase solid background color

  24. 24

    How can I remove onEvent from button widget in Corona?

  25. 25

    How to dynamically change SVG fill color?

  26. 26

    How to change default selection color of a ListView?

  27. 27

    How to change the color of the text of a label in Xcode

  28. 28

    How to change a font/background color in transparent windows?

  29. 29

    How to find and change color of specific word in string

뜨겁다태그

보관