Skip to content

Instantly share code, notes, and snippets.

@jwiese-ms-zz
Last active March 15, 2019 15:05
Show Gist options
  • Save jwiese-ms-zz/c463b7096c93cdab950d9e4c5eb4c445 to your computer and use it in GitHub Desktop.
Save jwiese-ms-zz/c463b7096c93cdab950d9e4c5eb4c445 to your computer and use it in GitHub Desktop.
Calibration Page
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
void _reporter(Offset global, Offset center) {
print( 'Touch: Global -> $global, Local -> $center');
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
canvasColor: Colors.white,
),
home: Material(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CalibrationPoint(reporter: _reporter),
CalibrationPoint(reporter: _reporter),
],
),
Container(
alignment: Alignment.center,
child: CalibrationPoint(reporter: _reporter),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
CalibrationPoint(reporter: _reporter),
CalibrationPoint(reporter: _reporter),
],
),
],
),
),
);
}
}
typedef ReportCalibration = void Function(Offset global, Offset center);
class CalibrationPoint extends StatelessWidget {
const CalibrationPoint({
Key key,
@required this.reporter,
}) : super(key: key);
final ReportCalibration reporter;
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTapDown: (details) => _handleTapDown(context, details),
child: Padding(
padding: const EdgeInsets.all(50.0),
child: Icon(Icons.add),
),
);
}
void _handleTapDown(BuildContext context, TapDownDetails details) {
final RenderBox renderBox = context.findRenderObject();
final centerPos = renderBox.localToGlobal(renderBox.size.center(Offset.zero));
reporter(details.globalPosition, centerPos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment