Я помещаю AnimationController в виджет PositionedTransition.
И я установил его дочерний элемент на виджет InkWell (или GestureDetector или IconButton), чтобы уловить поведение касания во время анимации.
Но это не работает. Если я нажму на это, ничего не произойдет.
Я хочу знать, зачем и как это делать.
Вместо этого теперь я помещаю виджет GestureDetector в то же положение.
спасибо за чтение и за хороший совет.
import 'package:flutter/material.dart';
import 'dart:math' as math;
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: Page0(),
);
}
}
class Page0 extends StatefulWidget {
@override
Page0State createState() => Page0State();
}
class Page0State extends State<Page0> with SingleTickerProviderStateMixin{
AnimationController _animationController;
var _isMoved = false;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 2000),
);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Stack(
children: <Widget> [
Container(
height : 800,
width : 800,
color : Colors.blue,
child :
GestureDetector(
onHorizontalDragEnd: null, //set no action
)
),
Positioned(
top:height/2,
left:width * 5/6-30,
child: InkWell(
onTap: (){debugPrint('a');},
child : Container(
height: 50,
width: 100,
),
),
),
PositionedTransition( //This widget!!!
child: //I set this child to IconButton
IconButton( //But it can't work
icon: Icon(
Icons.reply,
textDirection: TextDirection.rtl),
color: Colors.green,
onPressed: () {
debugPrint('bb'); //no debug
Navigator.push( //no push(Actually Page2 class exists.)
context,
_createNextRoute(Page2()));
},
),
rect: _animationController
.drive(
CurveTween(
curve: Curves.bounceIn,
),
)
.drive(
RelativeRectTween(
begin: RelativeRect.fromLTRB(width * 5/6 -20, height/2 , width / 6 +20, height/2 ),
end: RelativeRect.fromLTRB(width * 5/6, height/2, width / 6, height/2),
)
),
),
Positioned(
top:200,
left:200,
child:IconButton(
icon: Icon(Icons.forward),
onPressed: () {debugPrint('ccc');}, //this debug works well.
),
),
]
),
floatingActionButton: FloatingActionButton(
onPressed: () {
if (_isMoved) {
_animationController.repeat();
} else {
_animationController.reset();
_animationController.forward();
}
_isMoved = !_isMoved;
},
child:
Transform.rotate(
angle: math.pi, // 45 deg
child:Icon(Icons.reply,
textDirection: TextDirection.ltr,
color: Colors.greenAccent,
size: 36.0,
),
)
),
);
}
}
Route _createNextRoute(Widget classRtnWidget) {
return PageRouteBuilder(
pageBuilder: (context, animation,secondaryAnimation) => classRtnWidget,
transitionsBuilder: (context, animation, secondaryAnimation,child){
var begin = Offset(1.0,0.0);
var end = Offset.zero;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve:curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
);
}