简体   繁体   English

如何减小 Flutter 抽屉内开关小部件的宽度

[英]How do i decrease the width of a switch widget inside a drawer in Flutter

when i create a switch widget inside a drawer it takes all the width possible to fill the drawer width, i tried wrapping it with a Container and a sizedBox to decrease the its width but that didn't work.当我在抽屉内创建一个开关小部件时,它需要所有可能的宽度来填充抽屉宽度,我尝试用一个 Container 和一个 sizedBox 包装它以减小它的宽度,但这没有用。 here is an image that shows the result of my code这是显示我的代码结果的图像

app image here应用图片在这里

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

bool value = false;
bool newValue = true;

class _MainPageState extends State<MainPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test App'),
        centerTitle: true,
      ),
      drawer: Drawer(
        child: ListView(
          children: <Widget>[
            DrawerHeader(
              child: Text('Drawer Header'),
            ),
            ListTile(
              title: Text('Tile 1'),
            ),
            SizedBox(
              width: 50,
              child: Switch(
                value: value,
                onChanged: (bool newValue) {
                  setState(() {
                    value = newValue;
                  });
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}

Here's a fairly simple way to resolve.这是一个相当简单的解决方法。

Row(
   children: <Widget>[
      Switch(
           value: false,
           onChanged: null,
         ),
      Expanded(child: Container(),)
   ],
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM