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. here is an image that shows the result of my code
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(),)
],
),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.