Skip to content

Instantly share code, notes, and snippets.

@justinmc
Last active April 20, 2024 00:31
Show Gist options
  • Save justinmc/1c1cc652d2a0a84ef5a5b047b70bc1ea to your computer and use it in GitHub Desktop.
Save justinmc/1c1cc652d2a0a84ef5a5b047b70bc1ea to your computer and use it in GitHub Desktop.
Example of conflicting horizontal gesture recognizers
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() => runApp(const ExampleApp());
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Example'),
),
body: const Center(
child: ExampleHome(),
),
),
);
}
}
class ExampleHome extends StatelessWidget {
const ExampleHome({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
const SizedBox(height: 128.0),
MediaQuery(
data: const MediaQueryData(
gestureSettings: DeviceGestureSettings(touchSlop: 10.0),
),
child: RawGestureDetector(
gestures: <Type, GestureRecognizerFactory>{
TapAndHorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapAndHorizontalDragGestureRecognizer>(
() => TapAndHorizontalDragGestureRecognizer(),
(TapAndHorizontalDragGestureRecognizer instance) {
instance
..onDragStart = (TapDragStartDetails details) { print('justin outer start'); }
..onDragUpdate = (TapDragUpdateDetails details) { print('justin outer update'); }
..onDragEnd = (TapDragEndDetails details) { print('justin outer end'); };
},
),
},
child: Container(
color: Colors.blueGrey,
child: Padding(
padding: const EdgeInsets.all(32.0),
child: MediaQuery(
data: const MediaQueryData(
gestureSettings: DeviceGestureSettings(touchSlop: 11.0),
),
child: RawGestureDetector(
gestures: <Type, GestureRecognizerFactory>{
TapAndHorizontalDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapAndHorizontalDragGestureRecognizer>(
() => TapAndHorizontalDragGestureRecognizer(),
(TapAndHorizontalDragGestureRecognizer instance) {
instance
..onDragStart = (TapDragStartDetails details) { print('justin inner start'); }
..onDragUpdate = (TapDragUpdateDetails details) { print('justin inner update'); }
..onDragEnd = (TapDragEndDetails details) { print('justin inner end'); };
},
),
},
child: Container(
width: 100.0,
height: 100.0,
color: Colors.amberAccent,
),
),
),
),
),
),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment