There is a flutter package. I am the author of it. Idle logout, it does this.
https://pub.dev/packages/idle_logout