Flutter 如何让togglebutton占据容器中的整个空间?

Flutter 如何让togglebutton占据容器中的整个空间?,flutter,button,flutter-layout,Flutter,Button,Flutter Layout,我正试图通过togglebutton实现灵活的行为,我的togglebutton位于一个高度为60px、宽度为infinte的容器中,如何让togglebutton占据所有可用空间 遗憾的是,我不能使用MediaQuery,因为使用它会破坏我的下拉功能,还有其他方法吗 以下是切换按钮的代码: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all(

我正试图通过togglebutton实现灵活的行为,我的togglebutton位于一个高度为60px、宽度为infinte的容器中,如何让togglebutton占据所有可用空间

遗憾的是,我不能使用MediaQuery,因为使用它会破坏我的下拉功能,还有其他方法吗

以下是切换按钮的代码:

Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(
                  Radius.circular(10),
                ),
                color: Color.fromRGBO(108, 101, 172, 1),
              ),
              width: double.infinity,
              height: 60,
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 5, vertical: 5),
                child: ToggleButtons(
                  borderRadius: BorderRadius.all(
                    Radius.circular(10),
                  ),
                 textStyle: TextStyle(
                    fontWeight: FontWeight.w700,
                    fontFamily: 'OpenSans',
                    color: Colors.black,
                    fontSize: 17,
                  ),
                  selectedColor: Colors.black,
                  fillColor: Colors.white,
                  children: <Widget>[
                    Text('My country'),
                    Text('Global'),
                  ],
                  onPressed: (int index) {
                    setState(() {
                      for (int buttonIndex = 0;
                          buttonIndex < isSelected.length;
                          buttonIndex++) {
                        if (buttonIndex == index) {
                          isSelected[buttonIndex] = true;
                        } else {
                          isSelected[buttonIndex] = false;
                        }
                      }

                      if (index == 1) {
                        getGlobalResult();
                        isGlobal = true;
                        isTotal = true;
                      } else {
                        getCountryTotalResult(selectedValue);
                        isGlobal = false;
                        isTotal = true;
                        isDaySelected = [true, false, false];
                      }
                    });
                  },
                  isSelected: isSelected,
                ),
              ),
            ),
容器(
装饰:盒子装饰(
borderRadius:borderRadius.all(
圆形半径(10),
),
颜色:颜色。来自RGBO(108、101、172、1),
),
宽度:double.infinity,
身高:60,
孩子:填充(
填充:边缘组。对称(水平:5,垂直:5),
子:切换按钮(
borderRadius:borderRadius.all(
圆形半径(10),
),
textStyle:textStyle(
fontWeight:fontWeight.w700,
fontFamily:“OpenSans”,
颜色:颜色,黑色,
尺寸:17,
),
selectedColor:Colors.black,
fillColor:Colors.white,
儿童:[
文本(“我的国家”),
文本(“全局”),
],
onPressed:(int索引){
设置状态(){
对于(int buttonIndex=0;
按钮索引
这就是我得到的

我想要实现的目标(在有限制的情况下实现)

要获得全宽切换按钮,您可以使用
LayoutBuilder

LayoutBuilder(
  builder: (context, constraints) => ToggleButtons(
    constraints: BoxConstraints.expands(width: constraints.maxWidth/2),
    ....
    Your CODE
    ....
  )
);
这将动态地将
切换按钮扩展到全宽