Dart 颤振-动画中未检测到手势检测器
我正在使用一个动画,通过点击Dart 颤振-动画中未检测到手势检测器,dart,flutter,Dart,Flutter,我正在使用一个动画,通过点击FloatingActionButton在屏幕上填充蓝色。再次点击floatingAction按钮蓝色按钮退出屏幕。如下图所示: 我在动画中放置了一个GestureDetector,这样在屏幕充满蓝色后,当点击蓝色时,它就会退出屏幕。就像我再次点击了floatingAction按钮一样 然而,GestureDetector没有检测到屏幕上蓝色部分的任何点击,即使我将其放在onTap:({print(“test”)}GestureDetector没有检测到 有人能帮我
FloatingActionButton
在屏幕上填充蓝色。再次点击floatingAction按钮
蓝色按钮退出屏幕。如下图所示:
我在动画中放置了一个GestureDetector
,这样在屏幕充满蓝色后,当点击蓝色时,它就会退出屏幕。就像我再次点击了floatingAction按钮一样
然而,GestureDetector
没有检测到屏幕上蓝色部分的任何点击,即使我将其放在onTap:({print(“test”)}
GestureDetector
没有检测到
有人能帮我一下吗?点击蓝色按钮,它就可以再次运行\u up()
功能了
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
void main() {
runApp(new MaterialApp(home: new HomePage()));
}
class HomePage extends StatefulWidget {
@override
HomePageState createState() => new HomePageState();
}
class HomePageState extends State<HomePage> with TickerProviderStateMixin {
AnimationController _controller;
Animation<double> _animation;
bool upDown = true;
@override
void initState() {
_controller = new AnimationController(
vsync: this,
duration: const Duration(milliseconds: 180),
);
_animation = new CurvedAnimation(
parent: _controller,
curve: new Interval(0.0, 1.0, curve: Curves.linear),
);
}
@override
Widget build(BuildContext context) {
final ui.Size logicalSize = MediaQuery.of(context).size;
final double _width = logicalSize.width;
final double _height = logicalSize.height;
void _up(){
setState((){
if(upDown) {
upDown = false;
_controller.forward(from: 0.0);
} else {
upDown = true;
_controller.reverse(from: 1.0);
}
});
}
return new Scaffold(
body: new Stack(
children: <Widget>[
new Positioned(
bottom: 0.0,
child: new GestureDetector(
onTap: _up,
child: new AnimatedBuilder(
animation: _animation,
builder: (BuildContext context, Widget child) {
return new Container(
height: _height,
child: new CustomPaint(
painter: new Sky(_width, _height * _animation.value),
child: new Container(
height: _isRotated ? 0.0 : _height * _animation.value,
width: _isRotated ? 0.0 : _width,
),
),
);
},
),
)
),
new Positioned(
bottom: 16.0,
right: 16.0,
child: new FloatingActionButton(
backgroundColor: new Color(0xFFE57373),
child: new Icon(Icons.add),
onPressed: (){
_up();
},
)
)
]
)
);
}
}
class Sky extends CustomPainter {
final double _width;
double _rectHeight;
Sky(this._width, this._rectHeight);
@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(
new Rect.fromLTRB(
0.0, size.height - _rectHeight, this._width, size.height
),
new Paint()..color = new Color.fromRGBO(0, 153, 255, 0.9)
);
}
@override
bool shouldRepaint(Sky oldDelegate) {
return _width != oldDelegate._width || _rectHeight != oldDelegate._rectHeight;
}
}
导入“包装:颤振/材料.省道”;
将“dart:ui”导入为ui;
void main(){
runApp(新材料应用程序(主页:新主页());
}
类主页扩展了StatefulWidget{
@凌驾
HomePageState createState()=>新建HomePageState();
}
类HomePageState使用TickerProviderStateMixin扩展状态{
动画控制器_控制器;
动画(动画),;
bool upDown=true;
@凌驾
void initState(){
_控制器=新的AnimationController(
vsync:这个,,
持续时间:常量持续时间(毫秒:180),
);
_动画=新曲线动画(
父节点:_控制器,
曲线:新间隔(0.0,1.0,曲线:曲线。线性),
);
}
@凌驾
小部件构建(构建上下文){
final ui.Size logicalSize=MediaQuery.of(context.Size);
最终双宽度=logicalSize.width;
最终双倍高度=logicalSize.height;
作废{
设置状态(){
如果(向上向下){
向上向下=错误;
_控制器向前(起始:0.0);
}否则{
向上向下=真;
_控制器。反向(从:1.0);
}
});
}
归还新脚手架(
正文:新堆栈(
儿童:[
新定位(
底部:0.0,
儿童:新的手势检测器(
onTap:_up,
子对象:新的动画生成器(
动画:_动画,
生成器:(BuildContext上下文,小部件子项){
退回新货柜(
高度:_高度,
孩子:新油漆(
画家:新天空(_宽度,_高度*_动画.value),
子容器:新容器(
高度:_旋转?0.0:_高度*_动画值,
宽度:\旋转?0.0:\宽度,
),
),
);
},
),
)
),
新定位(
底部:16.0,
右图:16.0,
子:新的浮动操作按钮(
背景色:新颜色(0xFFE57373),
子:新图标(Icons.add),
已按下:(){
_up();
},
)
)
]
)
);
}
}
天空画师{
最终双倍宽度;
双倍高度;
天空(这个宽,这个高);
@凌驾
空心油漆(帆布,尺寸){
canvas.drawRect(
新建Rect.fromLTRB(
0.0,size.height-_recthheight,this._width,size.height
),
new Paint()…color=new color.fromRGBO(0,153255,0.9)
);
}
@凌驾
布尔应该重新绘制(天空旧代理){
返回_-width!=oldDelegate._-width | | | rectHeight!=oldDelegate._-rectHeight;
}
}
GestureDetector
只能在小部件上工作CustomPaint
不是一个小部件,因此有必要在CustomPaint
的child
属性中放入一个小部件,例如容器
以下是如何CustomPaint
:
...
child: new CustomPaint(
painter: new Sky(_width, _height * _animation.value),
child: new Container(
height: _isRotated ? 0.0 : _height * _animation.value,
width: _isRotated ? 0.0 : _width,
),
),
...
GestureDetector
只能在小部件上工作CustomPaint
不是一个小部件,因此有必要在CustomPaint
的child
属性中放入一个小部件,例如容器
以下是如何CustomPaint
:
...
child: new CustomPaint(
painter: new Sky(_width, _height * _animation.value),
child: new Container(
height: _isRotated ? 0.0 : _height * _animation.value,
width: _isRotated ? 0.0 : _width,
),
),
...
已经有东西为你做了:脚手架
使用Scaffold.of(上下文).showBottomSheet
它可以在一行代码中完成所有需要的操作
您还可以使用showModalBottomSheet
(它似乎有一个最大高度限制)
已经有东西为你做了:脚手架
使用Scaffold.of(上下文).showBottomSheet
它可以在一行代码中完成所有需要的操作
您还可以使用showModalBottomSheet
(它似乎有一个最大高度限制)