flutter:如何将RadioListTile按钮置于中心位置?

qaxu7uf2  于 2023-02-25  发布在  Flutter
关注(0)|答案(1)|浏览(164)

这是我的代码,我想我的中心radioListTile按钮。

import 'package:flutter/material.dart';

import '../Utils/GlobalColor/global_color.dart';
import '../Utils/GlobalTextStyles/global_text_styles.dart';
import '../Utils/GlobalWidgetPages/app_bar_center_text.dart';

class SavedAddressesPage extends StatefulWidget {
  const SavedAddressesPage({Key? key}) : super(key: key);

  @override
  State<SavedAddressesPage> createState() => _SavedAddressesPageState();
}

class _SavedAddressesPageState extends State<SavedAddressesPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MyColor.bgLightColor,
      appBar: AppBarWithCenterText(
        text: "Saved Addresses",
        onPressed: () {
          Navigator.pop(context);
        },
      ),
      body: Center(
        child: RadioListTile(
          dense: true,
          contentPadding: EdgeInsets.only(left: 13, right: 13, top: 0, bottom: 16),
          title: Container(
            padding: EdgeInsets.only(left: 13, right: 13, top: 16, bottom: 16),
            height: 100,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(8),
              border: Border.all(color: MyColor.greyColor),
            ),
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Image.asset(
                          "assets/outline_location_pin.png",
                          height: 18,
                          width: 17,
                          color: MyColor.blueColor,
                        ),
                        SizedBox(
                          width: 4,
                        ),
                        Text(
                          'Office',
                          style: textStyleWith14500(MyColor.blackColor),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                    Row(
                      children: [
                        InkWell(onTap: (){
                          print("edit");
                        },
                          child: Container(
                              height: 18,
                              width: 18,
                              child: Icon(
                                Icons.edit,
                                size: 16,
                                color: MyColor.blueColor,
                              )),
                        ),
                        SizedBox(
                          width: 14,
                        ),
                        InkWell(onTap: (){
                          print("delete_outline");
                        },
                          child:
                        Container(
                            height: 18,
                            width: 18,
                            child: Icon(
                              Icons.delete_outline,
                              size: 16,
                              color: MyColor.primaryRedColor,
                            )),)
                      ],
                    ),
                  ],
                ),
                SizedBox(
                  height: 9,
                ),
                Text(
                  "D-787 High Tower Appt., Flat No. 202, In White House Lane, Street View, USA.",
                  style: textStyleWith12400(MyColor.darkGreyColor),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
              ],
            ),
          ),
          value: "male",
          groupValue: 0,
          onChanged: (value) {
            setState(() {
              print(value.toString());
            });
          },
        ),
      ),
    );
  }
}

这是我的用户界面

但其实我想这样

v8wbuo2f

v8wbuo2f1#

这是可行的,但是使用RadioListTile在这种情况下没有多大意义。可以使用常规的ListTile将单选添加到前导中。

child: RadioListTile(
  controlAffinity: ListTileControlAffinity.trailing,
  secondary: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      Radio(value: 1, groupValue: 0, onChanged: (value) {}),
    ],
  ),
  // ...
),
child: ListTile(
  leading: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      Radio(value: 1, groupValue: 0, onChanged: (value) {}),
    ],
  ),
  // ...
),

相关问题