【问题标题】:How do i decrease the width of a switch widget inside a drawer in Flutter如何减少 Flutter 抽屉内的开关小部件的宽度
【发布时间】:2020-10-11 08:54:53
【问题描述】:

当我在抽屉内创建​​一个开关小部件时,它会占用所有可能的宽度来填充抽屉宽度, 我尝试用一​​个 Container 和一个 sizedBox 包装它以减小它的宽度,但这没有用。 这是显示我的代码结果的图像

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;
                  });
                },
              ),
            )
          ],
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: android windows android-studio flutter android-emulator


    【解决方案1】:

    这是一个相当简单的解决方法。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 2019-10-31
      • 2020-03-27
      • 2023-03-07
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多