Skip to content

Instantly share code, notes, and snippets.

@MariaMelnik
Last active February 6, 2019 15:04
Show Gist options
  • Save MariaMelnik/a8a3cfaeaf7dbc11ead0dd472790040d to your computer and use it in GitHub Desktop.
Save MariaMelnik/a8a3cfaeaf7dbc11ead0dd472790040d to your computer and use it in GitHub Desktop.
flutter: GestureDetector+transform issue
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
final double dyOffset = -100.0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Container(
height: 200.0,
width: 200.0,
color: Colors.green.withOpacity(0.3),
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Transform.translate(
offset: Offset(0.0, dyOffset),
child: GestureDetector(
onTap: _onTap,
child: FlutterLogo(size: 200.0,),
),
),
),
)
),
)
);
}
void _onTap(){
print("tap!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment