In Flutter, a positioned widget only responds to taps within its parent stack area by default. If you want a positioned widget to respond to taps outside of its parent stack area, you can use a combination of GestureDetector and a Stack with a larger size.
Here's how you can achieve this:
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: MyStack(), ), ), ); } } class MyStack extends StatelessWidget { @override Widget build(BuildContext context) { return GestureDetector( onTap: () { print("Tapped outside Positioned Widget"); }, child: Stack( alignment: Alignment.center, children: [ Container( color: Colors.blue.withOpacity(0.3), width: 200, height: 200, ), Positioned( top: 100, left: 100, child: GestureDetector( onTap: () { print("Tapped on Positioned Widget"); }, child: Container( color: Colors.red, width: 100, height: 100, ), ), ), ], ), ); } } In this example:
MyStack widget contains a Stack widget with a larger size.GestureDetector wraps the entire Stack widget to capture taps outside of the positioned widget's area.Stack, there's a positioned widget (Container with red color) that responds to taps within its area.With this setup, taps outside of the positioned widget's area will be captured by the GestureDetector wrapping the Stack, and taps within the positioned widget's area will be captured by the GestureDetector inside the positioned widget.
Flutter positioned Widget onTapOutside implementation
GestureDetector( onTap: () { // Handle tap inside Positioned widget area }, child: Stack( children: [ Positioned( left: 50, top: 50, child: Container( width: 100, height: 100, color: Colors.blue, ), ), GestureDetector( onTap: () { // Handle tap outside Positioned widget area }, child: Container( color: Colors.transparent, width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, ), ), ], ), ) Flutter detect tap outside Stack widget
GestureDetector( onTap: () { // Handle tap outside Stack widget }, child: Stack( children: [ Container( width: 200, height: 200, color: Colors.grey, ), ], ), ) Flutter Stack onTapOutside detection
GestureDetector( onTap: () { // Handle tap outside Stack widget }, child: Stack( children: [ Container( width: 200, height: 200, color: Colors.grey, ), ], ), ) Flutter detect tap outside Positioned widget
GestureDetector( onTap: () { // Handle tap outside Positioned widget }, child: Stack( children: [ Positioned( left: 50, top: 50, child: Container( width: 100, height: 100, color: Colors.blue, ), ), ], ), ) Flutter Positioned widget onTapOutside
GestureDetector( onTap: () { // Handle tap inside Positioned widget area }, child: Stack( children: [ Positioned( left: 50, top: 50, child: Container( width: 100, height: 100, color: Colors.blue, ), ), GestureDetector( onTap: () { // Handle tap outside Positioned widget area }, child: Container( color: Colors.transparent, width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, ), ), ], ), ) Flutter GestureDetector onTapOutside
GestureDetector( onTap: () { // Handle tap outside widget }, child: Container( width: 200, height: 200, color: Colors.grey, ), ) Flutter Stack widget detect tap outside
GestureDetector( onTap: () { // Handle tap outside Stack widget }, child: Stack( children: [ Container( width: 200, height: 200, color: Colors.grey, ), ], ), ) Flutter handle tap outside Positioned widget
GestureDetector( onTap: () { // Handle tap outside Positioned widget }, child: Stack( children: [ Positioned( left: 50, top: 50, child: Container( width: 100, height: 100, color: Colors.blue, ), ), ], ), ) Flutter Stack onTapOutside detection
GestureDetector( onTap: () { // Handle tap outside Stack widget }, child: Stack( children: [ Container( width: 200, height: 200, color: Colors.grey, ), ], ), ) Flutter Positioned widget tap detection outside
GestureDetector( onTap: () { // Handle tap inside Positioned widget area }, child: Stack( children: [ Positioned( left: 50, top: 50, child: Container( width: 100, height: 100, color: Colors.blue, ), ), GestureDetector( onTap: () { // Handle tap outside Positioned widget area }, child: Container( color: Colors.transparent, width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, ), ), ], ), ) msgpack spring-jms typeorm-activerecord getch rails-admin time-limiting code-snippets weblogic12c pygame-tick quartz