小编Tus*_*til的帖子

如何让切换按钮占据容器中的整个空间?

我正在尝试通过切换按钮实现灵活的行为,我的切换按钮位于高度为 60 像素且宽度无限的容器内,如何让切换按钮占用所有可用空间?

遗憾的是,我不能使用 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] = …
Run Code Online (Sandbox Code Playgroud)

button flutter flutter-layout

3
推荐指数
1
解决办法
681
查看次数

标签 统计

button ×1

flutter ×1

flutter-layout ×1