インターネットをチェックしても利用できません。次に、選択した吊り下げウィンドウウィジェットでリムーバブルウィジェットを共有します。
height このパラメータは、ウィジェットの子ウィジェットのデフォルトy軸位置です。
親コンテナはスタックであることを忘れないでください。
class MoveWidget extends StatefulWidget {
final Widget child;
final double height;
const MoveWidget({Key key, this.child, this.height}) : super(key: key);
@override
_MoveWidgetState createState() => _MoveWidgetState();
}
class _MoveWidgetState extends State<MoveWidget> {
double _bottom = 0.0;
double _left = 0.0;
double _right;
@override
void initState() {
_bottom = widget.height;
super.initState();
}
@override
Widget build(BuildContext context) {
return Positioned(
left: _left,
right: _right,
bottom:_bottom,
child: Material(
color: Colors.transparent,
child: GestureDetector(
onPanUpdate: (e) {
setState(() {
if(_left !=null){
_left = _left + e.delta.dx;
}else{
_right = _right-e.delta.dx;
}
_bottom = _bottom - e.delta.dy;
});
},
onPanEnd: (DragEndDetails details){
setState(() {
if(_left !=null){
if(_left>MediaQuery.of(context).size.width/2){
_left = null;
_right = 0;
}else{
_left = 0;
_right =null;
}
}else{
if(_right<MediaQuery.of(context).size.width/2){
_left = null;
_right = 0;
}else{
_left = 0;
_right =null;
}
}
if(_bottom <MediaQuery.of(context).padding.bottom){
_bottom = MediaQuery.of(context).padding.bottom;
}
});
},
child: widget.child ??
Container(
width: 100,
height: 100,
color: Colors.red,
child: Center(child: Text('ビューは追加されない')),
),
),
));
}
}