nisrulz / flutter-examples

[Examples] Simple basic isolated apps, for budding flutter devs.
https://nisrulz.com/flutter-examples/
Apache License 2.0
6.97k stars 1.67k forks source link

onClick #7

Closed ysnsyhn closed 4 years ago

ysnsyhn commented 6 years ago

how to make the grids clickable? I try to change to another layout when one of the items is clicked.

nisrulz commented 4 years ago

Wrap your grid item with GestureDetector.

i.e

GestureDetector(
  onTap: () {
    print("onTap called.");
  },
  child: Text("Hello World"),
),

Commit with change: https://github.com/nisrulz/flutter-examples/commit/034178da5b77174bc9d66ec9ce412c685ee82978

nisrulz commented 4 years ago

Forgot to mention, you can also use InkWell class which will enable ripple effect.

InkWell (
  onTap: () {
    print("onTap called.");
  },
  child: Text("Hello World"),
),

Depending on your use case, use either InkWell or GestureDetector

Read more : https://api.flutter.dev/flutter/material/InkWell-class.html