I have used a GestureDetector which is placed inside TabViewController. In that, the Pan and Tap events of Gesture Detector are not working and instead of that the drag and tap event of TabViewController is working. How to make the events of gesture detector to work?
I have referred this post but in that only the solution for avoiding the overridden of tap gesture of the corresponding widget has provided
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: DefaultTabController(length: 3, child: MyHomePage()),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _value = 10;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
title: Text('Tabs Demo'),
),
body: TabBarView(
children: <Widget>[
SingleChildScrollView(
child: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
ConstrainedBox(
constraints: BoxConstraints.loose(Size(200, 200)),
child: AspectRatio(
aspectRatio: 1,
child: GestureDetector(
onPanStart: (DragStartDetails details) =>
{print('pan start')},
onPanUpdate: (DragUpdateDetails details) =>
{print('pan update')},
onPanEnd: (DragEndDetails details) =>
{print('pan end')},
onTapUp: (TapUpDetails details) =>
{print('tap up')},
child: Container(
color: Colors.green,
),
))),
Padding(
padding: EdgeInsets.all(10),
child: Container(
height: 200,
width: 200,
color: Colors.lightBlue,
),
),
Container(
height: 200,
child: Slider(
value: _value.toDouble(),
min: 1.0,
max: 10.0,
divisions: 10,
activeColor: Colors.red,
inactiveColor: Colors.black,
label: 'Set a value',
onChanged: (double newValue) {
setState(() {
_value = newValue.round();
});
}),
),
Padding(
padding: EdgeInsets.all(10),
child: Container(
height: 200,
width: 200,
color: Colors.lightBlue,
),
),
Container(
height: 200,
child: Slider(
value: _value.toDouble(),
min: 1.0,
max: 10.0,
divisions: 10,
activeColor: Colors.red,
inactiveColor: Colors.black,
label: 'Set a value',
onChanged: (double newValue) {
setState(() {
_value = newValue.round();
});
}),
)
],
),
),
),
Container(
color: Colors.yellow,
),
Container(
color: Colors.red,
)
],
),
);
}
}