我想在颤振中做两件事:
- 更改 switchlisttile() 的标题和开关之间的空间。
- 将两个 switchlistTiles 并排放置。由于某种原因,这会导致颤动错误。
谢谢。
我想在颤振中做两件事:
谢谢。
在给出高度时我没有任何错误只是一个演示尝试它可能有助于导入'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
double ?height ;
double ?width ;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
height = MediaQuery.of(context).size.height;
width = MediaQuery.of(context).size.width;
bool ans = false;
bool anss = false;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: [
Container(
height: height!/10,
width: width!/2,
child: SwitchListTile(
title: const Text('Lights'),
value: ans,
onChanged: (bool value) {
setState(() {
ans = value;
});
},
secondary: const Icon(Icons.lightbulb_outline),
),
),
Container(
height: height!/10,
width: width!/2,
child: SwitchListTile(
title: const Text('hhh'),
value: anss,
onChanged: (bool value) {
setState(() {
anss = value;
});
},
secondary: const Icon(Icons.lightbulb_outline),
),
)
],
),
],
),
),
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}