gpt4 book ai didi

将容器滑动到另一个容器中以显示或隐藏一些图标,如工具栏

转载 作者:IT王子 更新时间:2023-10-29 07:07:47 26 4
gpt4 key购买 nike

在容器中,你假设我有 AppBar() 女巫,我想有另一个不可见的容器,就像这个屏幕截图:

enter image description here

另外两个容器是不可见的,我想通过从上到下或从下到上滑动来显示它们,以改变可见或不可见的可见性

从上到下滑动显示或滑动到顶部隐藏

enter image description here

从底部滑动到顶部显示或滑动到底部隐藏

enter image description here

有什么库可以实现这个滑动动画吗?

最佳答案

Image goes here


单击箭头以显示顶部/底部容器,然后隐藏这些新容器,您可以向上/向下拖动它们或简单地触摸它们。

void main() => runApp(MaterialApp(home: HomePage()));

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
static double _height = 100, _one = -_height, _two = _height;
final double _oneFixed = -_height;
final double _twoFixed = _height;
Duration _duration = Duration(milliseconds: 5);
bool _top = false, _bottom = false;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Slide")),
body: SizedBox(
height: _height,
child: Stack(
children: <Widget>[
Positioned(
left: 0,
right: 0,
height: _height,
child: GestureDetector(
onVerticalDragEnd: (details) {
if (details.velocity.pixelsPerSecond.dy >= 0) _toggleTop();
else _toggleBottom();
},
child: _myContainer(
color: Colors.yellow[800],
text: "Old Container",
child1: IconButton(
icon: Icon(Icons.arrow_downward),
onPressed: _toggleTop,
),
child2: IconButton(
icon: Icon(Icons.arrow_upward),
onPressed: _toggleBottom,
),
),
),
),
Positioned(
left: 0,
right: 0,
top: _one,
height: _height,
child: GestureDetector(
onTap: _toggleTop,
onPanEnd: (details) => _toggleTop(),
onPanUpdate: (details) {
_one += details.delta.dy;
if (_one >= 0) _one = 0;
if (_one <= _oneFixed) _one = _oneFixed;
setState(() {});
},
child: _myContainer(
color: _one >= _oneFixed + 1 ? Colors.red[800] : Colors.transparent,
text: "Upper Container",
),
),
),
Positioned(
left: 0,
right: 0,
top: _two,
height: _height,
child: GestureDetector(
onTap: _toggleBottom,
onPanEnd: (details) => _toggleBottom(),
onPanUpdate: (details) {
_two += details.delta.dy;
if (_two <= 0) _two = 0;
if (_two >= _twoFixed) _two = _twoFixed;
setState(() {});
},
child: _myContainer(
color: _two <= _twoFixed - 1 ? Colors.green[800] : Colors.transparent,
text: "Bottom Container",
),
),
),
],
),
),
);
}

void _toggleTop() {
_top = !_top;
Timer.periodic(_duration, (timer) {
if (_top) _one += 2;
else _one -= 2;

if (_one >= 0) {
_one = 0;
timer.cancel();
}
if (_one <= _oneFixed) {
_one = _oneFixed;
timer.cancel();
}
setState(() {});
});
}

void _toggleBottom() {
_bottom = !_bottom;
Timer.periodic(_duration, (timer) {
if (_bottom) _two -= 2;
else _two += 2;

if (_two <= 0) {
_two = 0;
timer.cancel();
}
if (_two >= _twoFixed) {
_two = _twoFixed;
timer.cancel();
}
setState(() {});
});
}

Widget _myContainer({Color color, String text, Widget child1, Widget child2, Function onTap}) {
Widget child;
if (child1 == null || child2 == null) {
child = Text(text, style: TextStyle(fontSize: 32, color: Colors.white, fontWeight: FontWeight.bold));
} else {
child = Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
child1,
child2,
],
);
}
return GestureDetector(
onTap: onTap,
child: Container(
color: color,
alignment: Alignment.center,
child: child,
),
);
}
}

关于将容器滑动到另一个容器中以显示或隐藏一些图标,如工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57149002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com