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

Viewed 43

I am using the checkbox in listtile in flutter(v3.0.4) like this:

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:

enter image description here

what should I do to make the checkbox always align to the center of vertical in the card component?

1 Answers

Try

Center(child: checkbox)

Or

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

Related