简体   繁体   English

是否可以在颤动中使复选框在 listtile 中对齐中心

[英]is it possible to make the checkbox align center in listtile in flutter

I am using the checkbox in listtile in flutter( v3.0.4 ) like this:我在flutter( v3.0.4 )中使用listtile中的复选框,如下所示:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @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> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
            child: Card(
                child: ListTile(
                    visualDensity: VisualDensity(vertical: 3), // to expand
                    title: Text("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"),
                    leading: Checkbox(
                        value: true,
                        onChanged: (bool? value) {
                          if (value!) {}
                        })))) // This trailing comma makes auto-formatting nicer for build methods.
        );
  }
}

when the listtile text expand, the checkbox always align to the top like this:当 listtile 文本展开时,复选框始终与顶部对齐,如下所示:

在此处输入图像描述

what should I do to make the checkbox always align to the center of vertical in the card component?我应该怎么做才能使复选框始终与卡片组件中的垂直中心对齐?

Try尝试

Center(child: checkbox)

Or或者

Centet(child:
Column(
mainAxisSize:MainAxisSize.min,
mainAxisAlignment:MainAxisAlignement.center,
crossAxisAlignment: crossAxisAlignment.Center,
Children: [ Checkbox()]

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

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