Skip to content

Instantly share code, notes, and snippets.

@timmaffett
Last active May 1, 2023 06:19
Show Gist options
  • Save timmaffett/8ced42a5d3d90fa549adb75bcfc4ef45 to your computer and use it in GitHub Desktop.
Save timmaffett/8ced42a5d3d90fa549adb75bcfc4ef45 to your computer and use it in GitHub Desktop.
wild-gorge-8043
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: Colors.blueGrey,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Listener(
behavior: HitTestBehavior.deferToChild, //<< Play with this to see different behaviors
onPointerDown: (details) {
print('OUTER onPointerDown: ${details.localPosition}');
},
onPointerMove: (details) {
print('OUTER onPointerMove: ${details.localPosition}');
},
// too noisy with onPointHover on outer also..
//onPointerHover: (details) {
// print('OUTER onPointerHover: ${details.localPosition}');
//},
child: Column( children:
[
Expanded( child:
Container(
color: Colors.blue,
child:
Center(
child: MyWidget(),
),
),
),
],
),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
const width = 240.0;
return Center(
child: Listener(
behavior: HitTestBehavior.opaque, //<< Play with this to see different behaviors
onPointerDown: (details) {
print('onPointerDown: ${details.localPosition}');
},
onPointerMove: (details) {
print('onPointerMove: ${details.localPosition}');
},
onPointerHover: (details) {
print('onPointerHover: ${details.localPosition}');
},
child: CircleAvatar(
radius: width / 2,
backgroundColor: Colors.black12,
child: Container(),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment