如何解决如何更改CheckboxListTile的高度?
不久,我需要将可选区域的高度减小。
文本和复选框的大小不错,但周围的框对于我要创建的清单来说太大了。
CheckBoxListTile current height vs. desired height
试图用Transform.scale包裹它,但是文本变得太小:
Transform.scale(
scale: 0.8,child: CheckBoxListTile(
title: const Text("Rinite alérgica"),value: timedilation != 1.0,controlAffinity: ListTileControlAffinity.leading,onChanged: (bool value) {
setState(() {
timedilation = value ? 2.0 : 1.0;
});
},),
试图用Container包装它,但是我收到屏幕上的溢出警告。
有人有更好的解决方案吗?
解决方法
您尝试过吗?
onPressed: () {
setState(() {
videoname="Video/Intro1.mp4";
print("$videoname");
});
},
,
当尝试调整 CheckboxListFile
的大小时,似乎 Google 实际上建议创建自定义 Tile 小部件并使用 Checkbox
小部件。
https://api.flutter.dev/flutter/material/CheckboxListTile-class.html#material.CheckboxListTile.3
查看已创建的 LabeledCheckbox 小部件。您可以非常轻松地修改所有组件以满足您的需要。例如,如果你想让 Widget 本身更小,你现在可以将它包装在一个容器中
/// Flutter code sample for CheckboxListTile
// ![Custom checkbox list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_custom.png)
//
// Here is an example of a custom LabeledCheckbox widget,but you can easily
// make your own configurable widget.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,home: Scaffold(
appBar: AppBar(title: const Text(_title)),body: const Center(
child: MyStatefulWidget(),),);
}
}
class LabeledCheckbox extends StatelessWidget {
const LabeledCheckbox({
Key key,@required this.label,@required this.padding,@required this.value,@required this.onChanged,}) : super(key: key);
final String label;
final EdgeInsets padding;
final bool value;
final Function onChanged;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
onChanged(!value);
},child: Container(
padding: padding,child: Row(
children: <Widget>[
Expanded(child: Text(label)),Checkbox(
value: value,onChanged: (bool newValue) {
onChanged(newValue);
},],);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
bool _isSelected = false;
@override
Widget build(BuildContext context) {
return LabeledCheckbox(
label: 'This is the label text',padding: const EdgeInsets.symmetric(horizontal: 20.0),value: _isSelected,onChanged: (bool newValue) {
setState(() {
_isSelected = newValue;
});
},);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。