gpt4 book ai didi

dart - OverflowBox,溢出的部分无法响应按钮?

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

我需要建一个bottomNavigationBar,带有一个垂直溢出的TabBar item,所以我尝试使用 OverflowBox,它看起来很有用。但是还有一个问题,溢出的部分无法响应按钮。

那么我应该怎么做才能让 GestureDetector 生效呢?或者您有其他方法来构建这样的 bottomNavigationBar 吗?非常感谢!

this is screen capture

这是 main.dart:

    import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'OverflowBox touch test'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => new _MyHomePageState();
}

List<Color> _colors = [
Colors.blue,
Colors.green,
Colors.yellow,
];

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin{
String _tip = "";
TabController controller;
@override
Widget build(BuildContext context) {

return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new TabBarView(
controller: controller,
children: <Widget>[
new Center(child: new Text("page 1")),
new Center(child: new Text("page 2")),
new Center(child: new Text("page 3")),
],
),
bottomNavigationBar: new Container(
height: 72.0,
alignment: Alignment.bottomCenter,
color: const Color.fromRGBO(45, 45, 45, 1.0),
child: new TabBar(
controller: controller,
indicatorWeight: 0.01,
tabs: <Widget>[
_getBarItem(0),
_getBarItem(1),
_getBarItem(2),
],
),
),
);
}
@override
void initState() {
super.initState();
controller = new TabController(length: 3, vsync: this);
}

@override
void dispose() {
controller.dispose();
super.dispose();
}
Widget _getBarItem(int idx){
Widget ret = new Container(
width: 80.0,
height: idx==1?120.0:50.0,
color: _colors[idx],
);
if(idx==1){
ret = new OverflowBox(
maxHeight: double.infinity,
alignment: Alignment.bottomCenter,
child: new Container(
color: Colors.black,
child: new GestureDetector(
onTapDown: (x){
controller.animateTo(idx);
},
child: ret,
),
),
);
}
return ret;
}
}

最佳答案

尝试让你的GestureDetector包裹你的OverflowBox

关于dart - OverflowBox,溢出的部分无法响应按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52135387/

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